[英]Trying to fix the position of Buttons
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但我希望 btn3 像这样在右侧
Here (1,2,3,4) are buttons with btn3 (buttons).这里 (1,2,3,4) 是带有 btn3(按钮)的按钮。
Thanks for advance.感谢您的提前。
I assume that you want the btn3
buttons in a vertical line to the right of the other buttons.我假设您希望
btn3
按钮位于其他按钮右侧的垂直线上。
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.有各种选项,
GridSizer
和FlexGridSizer
GridSizer
在脑海中,但在您的代码中,您已经引入了一个水平BoxSizer
但没有使用它,所以下面的代码将使用它。
Load the vertical boxsizers and then load those into the horizontal sizer.加载垂直 boxsizer,然后将它们加载到水平 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.