使用python软件如何关闭弹窗,关闭Kivy应用程序时如何显示弹出窗口

I would like to show a popup confirming the user would really like to close the application when it would normally close.

I would like to do this on an Android and Python 2.7

解决方案

app.stop() function is actually called when exiting Kivy app.

Customized this function as much as you like:

class MyApp(App):

def stop(self, *largs):

# Open the popup you want to open and declare callback if user pressed `Yes`

popup = ExitPopup(title="Are you sure?")

popup.bind(on_confirm=partial(self.close_app, *largs))

popup.open()

def close_app(self, *largs):

super(MyApp, self).stop(*largs)

class ExitPopup(Popup):

def __init__(self, **kwargs):

super(ExitPopup, self).__init__(**kwargs)

self.register_event_type('on_confirm')

def on_confirm(self)

pass

def on_button_yes(self)

self.dispatch('on_confirm')

In the kv file, bind on_release method of Yes button to the on_button_yes function.

If that button is presses, on_button_yes() would be called, hence on_confirm event would be dispatched, and the app will be closed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值