按我你的问题的理解,你的应用是不是当你点击关闭按钮,当你点击关闭按钮关闭(红色按钮与X在右上角)。
默认情况下你的应用程序应关闭。就你而言,在我看来,你已经将EVT_CLOSE
绑定到某个方法,该方法没有代码来关闭应用程序窗口。 例如。考虑下面的代码片段,我有意将EVT_CLOSE
事件绑定到名为closeWindow()
的方法。这种方法没有做什么,这就是为什么我在那里有关键字。现在,如果您执行下面的代码片段,则可以看到应用程序窗口不会关闭。
代码:
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()
我希望它是有用的。
在程序中使用EVT_CLOSE事件吗?也许你应该在Close()之后调用Destroy()?不知道你的程序结构和事件处理很难回答。 –