简体   繁体   English

wxPython window 不会关闭

[英]wxPython window won't close

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)

Could it be that quitApp is called by the system CloseEvent handler?会不会是系统 CloseEvent 处理程序调用了 quitApp? 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.在这种情况下,self.Close(true) 只会触发一个新的 CloseEvent,在这种情况下它将再次调用 quitApp 并显示一个新的对话框......等等。

I suggest you quit the application with sys.exit(0) instead of self.Close(true).我建议您使用 sys.exit(0) 而不是 self.Close(true) 退出应用程序。

Without knowing more (see my comment), I can take a few stabs:在不了解更多信息的情况下(请参阅我的评论),我可以采取一些措施:

  1. If self is an App, then self.ExitMainLoop() will close the program.如果self是一个 App,那么self.ExitMainLoop()将关闭程序。
  2. If self is a Frame, then self.Close(True) is appropriate.如果self是一个 Frame,那么self.Close(True)是合适的。
  3. If self is anything else, then sys.exit(0) will shut down the Python Interpreter and close the program.如果self是其他任何东西,那么sys.exit(0)将关闭 Python 解释器并关闭程序。

You'll need to provide more code.您需要提供更多代码。 It looks like something else is triggering the quitApp function.看起来其他东西正在触发quitApp function。 Your function right there doesn't loop.你的 function 没有循环。 It might be looping because it's trying to close and the event keeps getting called.它可能正在循环,因为它试图关闭并且事件不断被调用。 Try using self.Destroy() instead to close the frame.尝试使用self.Destroy()来关闭框架。

def CloseTheProgram( self, event ): dial = wx.MessageDialog(None, 'Are you sure you want to quit?','Quit', wx.YES | wx.NO) if dial.ShowModal() == wx.ID_YES: self.Close(True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM