I am trying to change the places of the buttons from left to right at the top.
Here is the code below:
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title, size = (200,300))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
p = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
for label in range(8):
b2 = wx.Button(p, label =str(label))
vbox.Add(b2,0,wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
for label in range(8):
b3 = wx.Button(p, label = "Btn3")
vbox.Add(b3,0,wx.RIGHT)
hbox = wx.BoxSizer(wx.HORIZONTAL)
p.SetSizer(vbox)
app = wx.App()
Example(None, title = 'BoxSizer demo')
app.MainLoop()
The output is showing like this:
But I want the btn3 to the right side like this
Here (1,2,3,4) are buttons with btn3 (buttons).
Thanks for advance.
I assume that you want the btn3
buttons in a vertical line to the right of the other buttons.
There are various options, GridSizer
and FlexGridSizer
spring to mind but in your code you have already introduced a horizontal BoxSizer
but not used it, so this code below will use that.
Load the vertical boxsizers and then load those into the horizontal sizer.
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title, size = (200,300))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
p = wx.Panel(self)
vbox1 = wx.BoxSizer(wx.VERTICAL)
vbox2 = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
for label in range(8):
b2 = wx.Button(p, label =str(label))
vbox1.Add(b2,0,0)
for label in range(8):
b3 = wx.Button(p, label = "Btn3")
vbox2.Add(b3,0,0)
hbox.Add(vbox1)
hbox.Add(vbox2)
p.SetSizer(hbox)
app = wx.App()
Example(None, title = 'BoxSizer demo')
app.MainLoop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.