如何使用按钮退出 Kivy 应用程序

2023-06-07Python开发问题
46

本文介绍了如何使用按钮退出 Kivy 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我只是在学习 Python 和 Kivy 框架.我似乎找不到任何能够使用链接到按钮的代码优雅地退出 Kivy 应用程序的具体完整示例.

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.

我发现了这样的 Kivy 代码片段

I have found Kivy code snippets like this

Button:
    id:btnExit
    text:"Exit"
    on_press: app.Exit()

但没有实现 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.

我已阅读 Android 和 iOS 样式指南声明程序不会以编程方式退出并让操作系统处理它,但我正在开发全屏无边框桌面应用程序,并且需要一种通过按下按钮退出程序的方法.

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.

推荐答案

尝试使用 App.get_running_app().stop().
有关详细信息,请阅读 Kivy 文档文章为函数.

这篇关于如何使用按钮退出 Kivy 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

pandas 有从特定日期开始的按月分组的方式吗?
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)...
2024-08-22 Python开发问题
10

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10