有没有办法通过点击右上角的“x”来防止关闭kivy窗口,直到满足特定条件为止?
最佳答案
您可以通过将窗口的 on_request_close
与一个函数绑定(bind)来检查是否满足条件:
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.label import Label
class Base(Label):
def __init__(self, **kwargs):
super(Base, self).__init__(**kwargs)
Window.bind(on_request_close=self.exit_check)
self.counter = 0
self.text = str(self.counter)
def exit_check(self, *args):
self.counter += 1
if self.counter < 5:
self.text = str(self.counter)
return True # block app's exit
else:
return False # let the app close
class SampleApp(App):
def build(self):
return Base()
if __name__ == "__main__":
SampleApp().run()
关于python - 如何防止在 kivy 应用程序中关闭 x 上的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55213183/