2014-10-20 8 views
0

我試圖做到這一點,但這不是幫助。它說MainFrame沒有屬性onButton1.Why這是說,??我該如何解決?我可以通過在wxpython程序中單擊按鈕來創建兩個窗口嗎?

另外,我不明白,使用分級機在wxpython.What的使用分級機的基本知識?

如果我短時間或短暫地得到答案,它將會幫助我很多。

class MainFrame(wx.Frame): 
    def __init__(self): 
     wx.Frame.__init__(self, None, wx.NewId(), "Main") 
     self.sizer = wx.BoxSizer(wx.VERTICAL) 


     self.button = wx.Button(self, wx.NewId(), "Open a window") 
     self.button1 = wx.Button(self, wx.NewId(), "Open another window") 
     self.sizer.Add(self.button, proportion=0, border=2, flag=wx.ALL) 
     self.SetSizer(self.sizer) 
     self.sizer.Add(self.button1, proportion=2, border=4, flag=wx.ALL) 
     self.SetSizer(self.sizer) 

     self.Bind(wx.EVT_BUTTON, self.onButton,self.button) 
     self.Bind(wx.EVT_BUTTON, self.onButton1, self.button1) 

     self.Layout() 

    def onButton(self, evt): 
     frame = NewFrame2(self) 
     frame.Show(True) 
     frame.MakeModal(True) 

class NewFrame2(wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__(self, parent, wx.NewId(), "Child") 
     panel=wx.Panel(self) 

    def onButton1(self, evt): 
     frame = NewFrame(self) 
     frame.Show(True) 
     frame.MakeModal(True) 


class NewFrame(wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__(self, parent, wx.NewId(), "Window") 
     panel=wx.Panel(self) 


class MyApp(wx.App): 
    def OnInit(self): 
     frame = MainFrame() 
     frame.Show(True) 
     self.SetTopWindow(frame) 
     return True 

app = MyApp(0) 
app.MainLoop() 
+0

這個wiki有一些關於sizers的很好的信息 - http://wiki.wxpython.org/UsingSizers – Werner 2014-10-21 06:06:22

回答

0

您需要定義onButton1MainFrame類裏面就像你與你的onButton方法一樣。由於它在NewFrame2中定義,該方法在範圍之外,不能從MainFrame類中綁定。

+0

謝謝你的幫助:) – 2014-10-20 18:36:42

相關問題