あなたの質問に対する私の理解によると、閉じるボタンをクリックしてもアプリケーションが閉じません (右上隅に X が付いた赤いボタン)。
デフォルトでは、閉じるボタンをクリックすると、アプリケーションが閉じます。あなたの場合EVT_CLOSE
、アプリウィンドウを閉じるためのコードが含まれていないメソッドにバインドしたようです。たとえば。以下のコード スニペットを検討してください。私は意図的にEVT_CLOSE
as という名前のメソッドにイベントをバインドしてい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()
お役に立てば幸いです。