python
1import wx 2 3class ChildFrame(wx.Frame): 4 def __init__(self,parent): 5 wx.Frame.__init__(self,parent,wx.ID_ANY,"child frame",pos=(100,100)) 6 7 pane2 = wx.Panel(self) 8 self.exitBtn = wx.Button(pane2,label="閉じる",pos=(100,10)) 9 self.Bind(wx.EVT_BUTTON,self.exit2,self.exitBtn) 10 11 def exit2(self,event): 12 # 画面を閉じるではなく非表示に 13 self.Show(False) 14 15class MyWindow(wx.Frame): 16 17 def __init__(self, parent, id): 18 wx.Frame.__init__(self,parent,wx.ID_ANY,"main frame") 19 panel = wx.Panel(self) 20 self.showChildBtn = wx.Button(panel,label="show child",pos=(10,10)) 21 self.exitBtn = wx.Button(panel,label="exit",pos=(100,10)) 22 self.Bind(wx.EVT_BUTTON,self.showChild,self.showChildBtn) 23 self.Bind(wx.EVT_BUTTON,self.exit,self.exitBtn) 24 # 子画面を生成する 25 self.childFrame = ChildFrame(self) 26 27 def showChild(self,event): 28 self.childFrame.Show() 29 return True 30 31 def exit(self, event): 32 self.childFrame.exit2(None) 33 34 35if __name__ == '__main__': 36 app = wx.App() 37 frame = MyWindow(parent=None,id=-1) 38 frame.Show() 39 app.MainLoop()
上のプログラムは、親画面から子画面の有無有無を操作するというものです。
<参照>親画面から子画面の表示イベントはできますが、子画面の閉じるイベントができない(teratail)
このプログラムの子画面の「閉じる」ボタンで親画面も子画面も終了させるには、
どのようにコードを書けば良いのでしょうか。
お分かりの方いらっしゃいましたら、ご教授いただければ幸いです。
あなたの回答
tips
プレビュー