基本wx尺寸问题

2024-10-02 20:33:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下尺寸相关代码:

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垂直延伸以适应整个桌子的高度。然而,虽然我有一个800x600窗口,wx.ListBox并没有扩展到整个高度。更确切地说,面板似乎确实展开了,但列表框没有:

Incorrect Layout 你知道吗

我做错了什么?你知道吗


Tags: selfaddtitleinitdefargskwargsclass
1条回答
网友
1楼 · 发布于 2024-10-02 20:33:12

proportion设置为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.

相关问题 更多 >