问题
Is it possible to have multiple panel in wxpython? I want to have something like this:
import wx.grid
import sys
class Mat_Frame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,wx.GetApp().TopWindow,title='Material Properties')
self.panel=wx.Panel(self,-1)
self.AdderPanel=wx.Panel(self.panel,-1)
self.InputPanel=wx.Panel(self.panel,-1)
self.OutputPanel=wx.Panel(self.panel,-1)
HorSizer=wx.BoxSizer(wx.HORIZONTAL)
HorSizer.Add(self.panel,proportion=1,flag=wx.EXPAND|wx.ALL)
HorSizer.Add(self.AdderPanel,proportion=1,flag=wx.EXPAND|wx.ALL)
HorSizer.Add(self.InputPanel,proportion=1,flag=wx.EXPAND|wx.ALL)
HorSizer.Add(self.OutputPanel,proportion=1,flag=wx.EXPAND|wx.ALL)
I tried this but it is not working. I mean, I get weird window unsized properly. Am I doing something wrong here? Can somebody point me how to use multiple panels in wxpython?
回答1:
You can create as many Panels as you want. You've only created one though, then a series of tuples. You may want this:
self.panel=wx.Panel(self,-1,size=(x,x))
panel1=wx.Panel(self.panel,-1,size=(x,x))
panel2=wx.Panel(self.panel,-1,size=(x,x))
That will actually create several Panels, with the second two being children of the first one. Their layout isn't going to be friendly yet though - you're going to need to look into Sizers.
回答2:
Sorry, I just realized I had forgotten to set the sizer. It worked fine after that.
来源:https://stackoverflow.com/questions/9706505/multiple-panel-in-wxpython