python - 基本的 wx 大小问题

标签 python user-interface layout wxpython sizer

我有以下与尺寸相关的代码:

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

Incorrect Layout

我做错了什么?

最佳答案

比例设置为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/

相关文章:

python - Paramiko 。按修改时间获取文件

java - 在 Spring MVC 中显示带有复选框的列表

java - Oracle 会创建一组在 Windows 8 上看起来原生的 UI 控件吗?

android - 使工具栏适合整个屏幕顶部

android - 在 ScrollView 屏幕底部定位按钮并设置比例宽度

android - 如何让按钮的高度与另一个元素的高度相匹配?

Python:如何使其不换行

python - 如何使用gunicorn 和多处理进行日志记录?

python - 如何获得转义字符的正确位置?

python - PyQt5鼠标悬停功能