我可以通过单击wxpython程序中的按钮来创建两个窗口吗?
我试过这样做,但这没有帮助。它说大型机在Button1上没有属性。为什么它会这样说?我如何解决这个问题 此外,我不了解sizer在wxpython中的用法。使用sizer的基本原理是什么 如果我能很快或很短地得到答案,这将对我有很大帮助我可以通过单击wxpython程序中的按钮来创建两个窗口吗?,wxpython,Wxpython,我试过这样做,但这没有帮助。它说大型机在Button1上没有属性。为什么它会这样说?我如何解决这个问题 此外,我不了解sizer在wxpython中的用法。使用sizer的基本原理是什么 如果我能很快或很短地得到答案,这将对我有很大帮助 class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.NewId(), "Main") self.sizer = w
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()
您需要在大型机类中定义onButton1,就像使用onButton方法一样。由于该方法是在NewFrame2中定义的,因此该方法超出了范围,无法从MainFrame类中绑定到该方法。感谢您的帮助:wiki提供了一些有关Sizer的好信息-