Python 如何使用按钮退出 Kivy 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32425831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exit a Kivy application using a button
提问by Ballew
I'm just learning Python and the Kivy framework. I can't seem to find any specific complete examples of being able to gracefully exit a Kivy app using code linked to a button.
我只是在学习 Python 和 Kivy 框架。我似乎找不到任何能够使用链接到按钮的代码优雅退出 Kivy 应用程序的具体完整示例。
I have found Kivy code snippets like this
我找到了这样的 Kivy 代码片段
Button:
id:btnExit
text:"Exit"
on_press: app.Exit()
But not any matching code that implements the app.Exit()
call. Everything I've tried stops code execution but doesn't clean up the program window.
但不是任何实现app.Exit()
调用的匹配代码。我尝试过的一切都会停止代码执行,但不会清理程序窗口。
I've read that Android and iOS style guides state that a program is not to programmatically exit and let the OS handle it but I am developing fullscreen borderless Desktop app and need a way to exit the program with a button press.
我读过 Android 和 iOS 风格指南指出程序不是以编程方式退出并让操作系统处理它,但我正在开发全屏无边框桌面应用程序,需要一种通过按下按钮退出程序的方法。
采纳答案by M.A.K. Ripon
Try using App.get_running_app().stop()
.
For more details, read the Kivy documentation articlefor the function.
尝试使用App.get_running_app().stop()
.
有关更多详细信息,请阅读该函数的Kivy 文档文章。
回答by Ruben G
回答by Sunil_Gupta
Try using self.root_window.close()
.
There is bug in new android toolchain.
尝试使用self.root_window.close()
. 新的 android 工具链中存在错误。