我有以下与尺寸相关的代码:
import wx
class TableSelectPanel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
wx.Panel.__init__(self, parent, *args, **kwargs)
self.title = wx.StaticText(self, label="Select Table")
self.tableList = wx.ListBox(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.title)
sizer.Add(self.tableList, flag=wx.EXPAND)
self.SetSizerAndFit(sizer)
class LobbyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.tableSelect = TableSelectPanel(self)
#window size
self.SetMinSize((800, 600))
self.SetMaxSize((800, 600))
self.SetSize((800, 600))
#sizers
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.tableSelect, flag=wx.EXPAND)
self.SetSizer(sizer)
self.Show(True)
我期望的是,我将有一个 800x600 的窗口,其中 wx.ListBox
垂直拉伸(stretch)以适合表格的整个高度。但是,虽然我有一个 800x600 的窗口,但 wx.ListBox
不会扩展到整个高度。相反,面板似乎确实拉伸(stretch),但列表框没有拉伸(stretch):
我做错了什么?
最佳答案
将比例
设置为1:
sizer.Add(self.tableList, proportion=1, flag=wx.EXPAND)
Although the meaning of this parameter is undefined in wxSizer, it is used in wxBoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wxBoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wxBoxSizer. For example, you might have a horizontal wxBoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer's horizontal dimension.
关于python - 基本的 wx 大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367192/