Python:wxPython:GridBagSizer 布局管理帮助

发布于 2024-12-19 21:17:57 字数 1951 浏览 0 评论 0原文

我在尝试调整控件大小时遇到​​问题,有人可以指出哪里需要修正才能使控件堆叠整齐吗?

即 TextCtrl 框应为标准默认大小。

和阅读与将按钮设置为堆叠在 TextCtrl 框的正下方。

Screenshot

这是我的代码:

class AVMCPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        #create the grouping box and sizer for the outline
        self.box = wx.StaticBox(self, -1, "AVMC CONTROL PANEL")
        self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)

        #create the sizer and place controls within box
        self.gbs = wx.GridBagSizer(5,5)

        self.sampleList = ['zero', 'one', 'two', 'three', 'four'] #temp list items
        self.t1 = wx.StaticText(self, label="Power Rail to margin:")
        self.lb1 = wx.ListBox(self, 1, (100, 50), (150, 120), self.sampleList, wx.LB_SINGLE)
        self.t2 = wx.StaticText(self, label="Read Voltage:")
        self.t3 = wx.StaticText(self, label="Set Voltage:")
        self.read_btn = wx.Button(self, 1, "  Read  ", (-1,-1) )
        self.set_btn = wx.Button(self, 1, "  Set  ", (-1,-1))
        self.rtext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)
        self.stext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)

        self.gbs.Add(self.t1, (0,0))
        self.gbs.Add(self.lb1, (1,0))
        self.gbs.Add(self.t2, (0,5))
        self.gbs.Add(self.t3, (0,10))
        self.gbs.Add(self.read_btn, (2,5))
        self.gbs.Add(self.set_btn, (2,10))
        self.gbs.Add(self.rtext, (1,5))
        self.gbs.Add(self.stext, (1,10))


        #Place the control inside group box
        self.bsizer.Add(self.gbs, 0, flag=wx.ALL, border=5)

        #Place the static group box sizer within the border frame
        #Creating a border that the static box will sit inside
        self.border = wx.BoxSizer()
        self.border.Add(self.bsizer, 1000, wx.ALL, 10)
        self.SetSizer(self.border)

谢谢。

I got an problem trying to resize the controls, could someone point out where needs correction for a tidy controls stack up?

i.e. the TextCtrl boxes should be standard default sizes.

and The Read & Set buttons to be stacked just right below the TextCtrl boxes.

Screenshot

Here's my code:

class AVMCPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        #create the grouping box and sizer for the outline
        self.box = wx.StaticBox(self, -1, "AVMC CONTROL PANEL")
        self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)

        #create the sizer and place controls within box
        self.gbs = wx.GridBagSizer(5,5)

        self.sampleList = ['zero', 'one', 'two', 'three', 'four'] #temp list items
        self.t1 = wx.StaticText(self, label="Power Rail to margin:")
        self.lb1 = wx.ListBox(self, 1, (100, 50), (150, 120), self.sampleList, wx.LB_SINGLE)
        self.t2 = wx.StaticText(self, label="Read Voltage:")
        self.t3 = wx.StaticText(self, label="Set Voltage:")
        self.read_btn = wx.Button(self, 1, "  Read  ", (-1,-1) )
        self.set_btn = wx.Button(self, 1, "  Set  ", (-1,-1))
        self.rtext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)
        self.stext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)

        self.gbs.Add(self.t1, (0,0))
        self.gbs.Add(self.lb1, (1,0))
        self.gbs.Add(self.t2, (0,5))
        self.gbs.Add(self.t3, (0,10))
        self.gbs.Add(self.read_btn, (2,5))
        self.gbs.Add(self.set_btn, (2,10))
        self.gbs.Add(self.rtext, (1,5))
        self.gbs.Add(self.stext, (1,10))


        #Place the control inside group box
        self.bsizer.Add(self.gbs, 0, flag=wx.ALL, border=5)

        #Place the static group box sizer within the border frame
        #Creating a border that the static box will sit inside
        self.border = wx.BoxSizer()
        self.border.Add(self.bsizer, 1000, wx.ALL, 10)
        self.SetSizer(self.border)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-12-26 21:17:57

在以下代码中:

self.rtext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)
self.stext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)

您正在 TextCtrl 上使用 Sizer 标志。删除它可以防止 TextCtrl 垂直变高。

您的按钮正在下降,因为列表框正在加宽其上方的行。使用以下命令使列表框跨越两行:

self.gbs.Add(self.lb1, (1,0), span=wx.GBSpan(2,1))

In the following code:

self.rtext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)
self.stext = wx.TextCtrl(self, 1, "", size=(80, -1), style=wx.ALL)

You are using a Sizer flag on a TextCtrl. Remove this to prevent the TextCtrl from being vertically taller.

Your buttons are going down because the ListBox is widening the row above it. Make the ListBox span over two rows with the following:

self.gbs.Add(self.lb1, (1,0), span=wx.GBSpan(2,1))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文