gpt4 book ai didi

python - wxpython:我将如何配置一个 box sizer 以便它有一个中心列在调整大小时移动,但不会改变尺寸(里面的图片解释)

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:19 29 4
gpt4 key购买 nike

我不知道如何嵌套我的 sizer 以便我得到以下行为。

enter image description here

当用户调整窗口大小时,我希望所有小部件的配置保持不变,但让包含所有内容的中央列保持居中。

最佳答案

使用 box sizer,您应该相应地调整比例。侧面的垫片应填充剩余空间,而中间部分应有固定的空间。查看documentation of wx.BoxSizer :

It is the unique feature of a box sizer, that it can grow in both directions (height and width) but can distribute its growth in the main direction (horizontal for a row) unevenly among its children. This is determined by the proportion parameter give to items when they are added to the sizer. It is interpreted as a weight factor, i.e. it can be zero, indicating that the window may not be resized at all, or above zero. If several windows have a value above zero, the value is interpreted relative to the sum of all weight factors of the sizer, so when adding two windows with a value of 1, they will both get resized equally and each will receive half of the available space after the fixed size items have been sized.

另请参阅这个小示例代码(使用 wxFormBuilder 生成)。我已经强调,间隔符的比例为 1,而应用程序的比例为 0

class MyFrame1 (wx.Frame):
def __init__(self):
super(MyFrame1, self).__init__()

fluid_sizer = wx.BoxSizer(wx.HORIZONTAL)
fluid_sizer.AddSpacer((0, 0), 1, wx.EXPAND, 5)
# ^--- proportion = 1

self.fixed_panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.Size(-1,-1), wx.TAB_TRAVERSAL)
self.fixed_panel.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT))
fixed_sizer = wx.BoxSizer(wx.VERTICAL)
fixed_sizer.SetMinSize(wx.Size(150,-1))
self.m_button1 = wx.Button(self.fixed_panel, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fixed_sizer.Add(self.m_button1, 0, wx.ALL, 5)
self.fixed_panel.SetSizer(fixed_sizer)
self.fixed_panel.Layout()
fixed_sizer.Fit(self.fixed_panel)

fluid_sizer.Add(self.fixed_panel, 0, wx.EXPAND |wx.ALL, 5)
# ^--- proportion = 0


fluid_sizer.AddSpacer((0, 0), 1, wx.EXPAND, 5)
# ^--- proportion = 1

self.SetSizer(fluid_sizer)
self.Layout()

Preview of example code

关于python - wxpython:我将如何配置一个 box sizer 以便它有一个中心列在调整大小时移动,但不会改变尺寸(里面的图片解释),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14266161/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com