如何防止在Kivy App中关闭X上的窗口 [英] How to prevent closing window on x in kivy app

查看:86
本文介绍了如何防止在Kivy App中关闭X上的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过单击右上角的"x"直到满足特定条件来防止关闭奇异果窗口?

Is there a way to prevent closing kivy window by clicking 'x' in top right corner until a certain condition is met?

推荐答案

您可以通过将窗口的on_request_close与函数绑定来检查条件是否满足:

You can do it by binding the window's on_request_close with a function to check if the conditions are met:

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()

这篇关于如何防止在Kivy App中关闭X上的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆