11
我想在主框架的子框架wxPython中創建一個新框架,以便當主框架關閉時,子框架也將被關閉。在wxPython中創建主框架的子框架
這是我遇到的問題的一個簡單的例子:
#! /usr/bin/env python
import wx
class App(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show()
self.SetTopWindow(frame)
return True
class MainFrame(wx.Frame):
title = "Main Frame"
def __init__(self):
wx.Frame.__init__(self, None, 1, self.title) #id = 5
menuFile = wx.Menu()
menuAbout = wx.Menu()
menuAbout.Append(2, "&About...", "About this program")
menuBar = wx.MenuBar()
menuBar.Append(menuAbout, "&Help")
self.SetMenuBar(menuBar)
self.CreateStatusBar()
self.Bind(wx.EVT_MENU, self.OnAbout, id=2)
def OnQuit(self, event):
self.Close()
def OnAbout(self, event):
AboutFrame().Show()
class AboutFrame(wx.Frame):
title = "About this program"
def __init__(self):
wx.Frame.__init__(self, 1, -1, self.title) #trying to set parent=1 (id of MainFrame())
if __name__ == '__main__':
app = App(False)
app.MainLoop()
如果我設置AboutFrame的父框架無(上線48),那麼關於幀被成功地創建並顯示,但它保持開放當主框架關閉時。
這是我應該採取的方法來創建主框架的子框架,或者我應該採取不同的方式,例如。使用主框架的onClose事件關閉任何子框架(這種方式聽起來非常「黑客」)。
如果我採取正確的方法,爲什麼它不起作用?