我有一个用Kivy创建的弹出窗口,其中包含2个按钮。用户可以通过按弹出区域之外的按钮(auto_dismission=True)或单击“否”按钮来关闭弹出窗口。
选择“是”按钮,将退出整个应用程序。在
请参阅相关代码:class ExitApp(App):
def exit_confirmation(self):
# popup can only have one Widget. This can be fixed by adding a BoxLayout
self.box_popup = BoxLayout(orientation = 'horizontal')
self.box_popup.add_widget(Label(text = "Really exit?"))
self.box_popup.add_widget(Button(
text = "Yes",
on_press = ExitApp.exit,
size_hint = (0.215, 0.075)))
self.box_popup.add_widget(Button(
text = "No",
on_press = self.popup_exit.dismiss,
size_hint=(0.215, 0.075)))
self.popup_exit = Popup(title = "Exit",
content = self.box_popup,
size_hint = (0.4, 0.4),
auto_dismiss = True)
self.popup_exit.open()
def exit(self):
App.get_running_app().stop()
现在的问题在于按下“否”按钮。当按下时,代码将退出,并出现以下错误:on_press = self.popup_exit.dismiss,
AttributeError: 'Button' object has no attribute 'popup_exit'
你知道我怎样才能尽可能容易地解决这个问题吗?在