Python:wxPython:GridBagSizer布局管理帮助 [英] Python: wxPython: Help on GridBagSizer Layout Management

查看:289
本文介绍了Python:wxPython:GridBagSizer布局管理帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试调整控件大小时遇到​​问题,有人可以指出需要在哪里纠正整齐的控件吗?

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

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

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

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

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

这是我的代码:

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)

谢谢.

推荐答案

在以下代码中:

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垂直变高.

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

您的按钮正在下降,因为ListBox扩大了它上面的行.使用以下命令使ListBox跨两行:

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))

这篇关于Python:wxPython:GridBagSizer布局管理帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆