根据我对您的问题的理解,当您单击关闭按钮时,您的应用程序没有关闭(右上角带有 X 的红色按钮。)
默认情况下,当您单击关闭按钮时,您的应用程序应该关闭。在您的情况下,在我看来,您已将其绑定EVT_CLOSE
到某个方法,其中没有用于关闭应用程序窗口的代码。例如。考虑下面的代码片段,我有意将EVT_CLOSE
事件绑定到名为closeWindow()
. 这个方法什么也没做,这就是我在pass
那里有关键字的原因。现在,如果您执行下面的代码片段,您可以看到应用程序窗口不会关闭。
代码:
import wx
class GUI(wx.Frame):
def __init__(self, parent, id, title):
screenWidth = 500
screenHeight = 400
screenSize = (screenWidth,screenHeight)
wx.Frame.__init__(self, None, id, title, size=screenSize)
self.Bind(wx.EVT_CLOSE, self.closeWindow) #Bind the EVT_CLOSE event to closeWindow()
def closeWindow(self, event):
pass #This won't let the app to close
if __name__=='__main__':
app = wx.App(False)
frame = GUI(parent=None, id=-1, title="Problem Demo-PSS")
frame.Show()
app.MainLoop()
因此,为了关闭应用程序窗口,您需要更改closeWindow()
. 例如:当您单击关闭按钮时,以下代码片段将使用Destroy()关闭应用程序窗口。
import wx
class GUI(wx.Frame):
def __init__(self, parent, id, title):
screenWidth = 500
screenHeight = 400
screenSize = (screenWidth,screenHeight)
wx.Frame.__init__(self, None, id, title, size=screenSize)
self.Bind(wx.EVT_CLOSE, self.closeWindow) #Bind the EVT_CLOSE event to closeWindow()
def closeWindow(self, event):
self.Destroy() #This will close the app window.
if __name__=='__main__':
app = wx.App(False)
frame = GUI(parent=None, id=-1, title="Problem Demo-PSS")
frame.Show()
app.MainLoop()
我希望它有用。