wxPython 窗口不会关闭
当您单击“取消”时,它会取消...当您单击“确定”时,它会重新弹出对话框。我该如何解决这个问题?
def quitApp(self, event):
dial = wx.MessageDialog(None, 'Are you sure you want to quit?','Quit', wxYES | wxNO)
if dial.ShowModal() == wxID_YES:
self.Close(true)
When you click on Cancel, it cancels... When you click OK, it pops the dialog back on. How can I fix this?
def quitApp(self, event):
dial = wx.MessageDialog(None, 'Are you sure you want to quit?','Quit', wxYES | wxNO)
if dial.ShowModal() == wxID_YES:
self.Close(true)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
难道 quitApp 是由系统 CloseEvent 处理程序调用的吗?在这种情况下, self.Close(true) 只会触发一个新的 CloseEvent,在这种情况下,它将再次调用 quitApp 并显示一个新的对话框......等等。
我建议您使用 sys.exit(0) 而不是 self.Close(true) 退出应用程序。
Could it be that quitApp is called by the system CloseEvent handler? In that case, self.Close(true) only triggers a new CloseEvent, which in that case will call quitApp again and show a new dialog... and so on.
I suggest you quit the application with sys.exit(0) instead of self.Close(true).
在不了解更多信息的情况下(请参阅我的评论),我可以采取一些措施:
self
是一个应用程序,则self.ExitMainLoop()
将关闭程序。self
是一个 Frame,则self.Close(True)
是合适的。self
是其他内容,则sys.exit(0)
将关闭 Python 解释器并关闭程序。Without knowing more (see my comment), I can take a few stabs:
self
is an App, thenself.ExitMainLoop()
will close the program.self
is a Frame, thenself.Close(True)
is appropriate.self
is anything else, thensys.exit(0)
will shut down the Python Interpreter and close the program.您需要提供更多代码。看起来有其他东西正在触发
quitApp
函数。你的函数不会循环。它可能正在循环,因为它正在尝试关闭并且事件不断被调用。尝试使用 self.Destroy() 来关闭框架。You'll need to provide more code. It looks like something else is triggering the
quitApp
function. Your function right there doesn't loop. It might be looping because it's trying to close and the event keeps getting called. Try usingself.Destroy()
instead to close the frame.