Reputation: 25
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title,size=(250, 250))
panel1 = wx.Panel(self, -1,pos=(0,100),size=(100,100))
button1 = wx.Button(panel1, -1, label="click me")
panel2 = wx.Panel(self, -1,pos=(0,200))
button2 = wx.Button(panel2, -1, label="click me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel1,0,wx.EXPAND|wx.ALL,border=10)
sizer.Add(panel2,0,wx.EXPAND|wx.ALL,border=10)
self.SetSizer(sizer)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'frame')
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()
I want to test two panel layout in wxpython , i change the pos(x,y) but it does't work . so how to layout just use boxsizer and panel ?
Upvotes: 1
Views: 7536
Reputation: 33071
I'm not sure what you're asking. If you use a sizer, then you cannot provide x/y coordinates to position the widgets. If you're just wondering why the panels look weird, it's because you don't have a normal panel underneath them. The code below is one way to fix that. The other way would be to give each of the panels you had a proportion greater than zero when adding them to the BoxSizer.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title,size=(250, 250))
topPanel = wx.Panel(self)
panel1 = wx.Panel(topPanel, -1,pos=(0,100),size=(100,100))
button1 = wx.Button(panel1, -1, label="click me")
panel2 = wx.Panel(topPanel, -1,pos=(0,200))
button2 = wx.Button(panel2, -1, label="click me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel1,0,wx.EXPAND|wx.ALL,border=10)
sizer.Add(panel2,0,wx.EXPAND|wx.ALL,border=10)
topPanel.SetSizer(sizer)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'frame')
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()
Upvotes: 3