python - wxpython中的对象对齐

标签 python wxpython

我向 BoxSizer 添加了一些按钮。 这是我想要的: enter image description here

这就是我要去的地方: enter image description here

这是第二个盒子的代码:

    self.approveItem = wx.Button(self.panel_1, -1, "Approve Item")
    self.changeQty = wx.Button(self.panel_1, -1, "Change Qty")
    sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
    sizer_2.Add(self.approveItem, 0, wx.ALIGN_RIGHT | wx.RIGHT, 0)
    sizer_2.Add(self.changeQty, 0, wx.ALIGN_RIGHT| wx.RIGHT, 0)
    self.sizer_item_staticbox = wx.StaticBox(self, -1, "")
    sizer_item = wx.StaticBoxSizer(self.sizer_item_staticbox, wx.HORIZONTAL)
    sizer_item.SetMinSize((600,-1))
    sizer_item.Add(sizer_2, 0, wx.EXPAND, 0)    

我该如何解决?

最佳答案

有很多方法可以实现您想要的效果,包括使用 flexgridsizer、gridsizer 和普通的水平和垂直 boxsizer,这里是一个 gridsizer 示例。
我将其设置为 5 列宽,以便您可以根据需要在左侧插入额外的按钮。
请参阅:http://wxpython.org/Phoenix/docs/html/GridSizer.html

#!/usr/bin/env python
import wx
class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition)
        Buttons = []
        Buttons.append(wx.Button(self,-1, "Approve Location"))
        Buttons.append(wx.Button(self,-1, "Approve Item"))
        Buttons.append(wx.Button(self,-1, "Change Qty"))
        Buttons.append(wx.Button(self,-1, "Approve"))
        sizer = wx.GridBagSizer(5,3)
        sizer.Add(Buttons[0], (0, 5), (1,1), wx.EXPAND)
        sizer.Add(Buttons[1], (1, 4), (1,1), wx.EXPAND)
        sizer.Add(Buttons[2], (1, 5), (1,1), wx.EXPAND)
        sizer.Add(Buttons[3], (2, 5), (1,1), wx.EXPAND)
        self.SetSizerAndFit(sizer)
        self.Centre()
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "Gridbagsizer")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True
if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

关于python - wxpython中的对象对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649980/

相关文章:

python - 使用 login_required 的装饰器 : flask/flask_login,

python ObjectListView 用空行更新显示,即使列表具有有效数据

python - 你如何在cygwin下编译wxPython?

python - 如何在wxPython中使用鼠标旋转matplotlib 3D绘图?

python-2.7 - 在 python 中的单独窗口中读取命令提示符输出

python - 创建列表以填充组合框时出错

python - 迭代 python 字典中的单个维度

python - 如何使用 Reportlab 在单个段落中的行之间添加空格

python - 烦人的 Twisted Python 问题

python - 按列中的唯一值拆分 numpy 数组