wxPython:如何修复网格大小调整器的一部分的大小

发布于 2024-11-09 21:42:28 字数 2019 浏览 0 评论 0原文

我想要做的是创建 3 列,该列将随着窗口的扩展而扩展。但我想对其施加限制,以便不同的列扩展到不同的最大数量。

我在这里所做的是使用 wxGlade 创建一个带有 1 行和 3 列的网格大小调整器的框架。我希望 Part1 具有固定宽度“A”,Part2 具有固定宽度“B”,Part3 能够正常扩展。

我该怎么做?

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Tue May 24 11:35:21 2011

import wx

# begin wxGlade: extracode
# end wxGlade



class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        self.sizer_10_staticbox = wx.StaticBox(self.panel_1, -1, "Part2")
        self.sizer_11_staticbox = wx.StaticBox(self.panel_1, -1, "Part3")
        self.sizer_9_staticbox = wx.StaticBox(self.panel_1, -1, "Part1")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame1.__set_properties
        self.SetTitle("frame_2")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_4 = wx.GridSizer(1, 3, 0, 0)
        sizer_11 = wx.StaticBoxSizer(self.sizer_11_staticbox, wx.HORIZONTAL)
        sizer_10 = wx.StaticBoxSizer(self.sizer_10_staticbox, wx.HORIZONTAL)
        sizer_9 = wx.StaticBoxSizer(self.sizer_9_staticbox, wx.HORIZONTAL)
        grid_sizer_4.Add(sizer_9, 1, wx.EXPAND, 0)
        grid_sizer_4.Add(sizer_10, 1, wx.EXPAND, 0)
        grid_sizer_4.Add(sizer_11, 1, wx.EXPAND, 0)
        self.panel_1.SetSizer(grid_sizer_4)
        sizer_8.Add(self.panel_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_8)
        sizer_8.Fit(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame1


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_2 = MyFrame1(None, -1, "")
    app.SetTopWindow(frame_2)
    frame_2.Show()
    app.MainLoop()

What I want to do is create 3 column that will expand as the window expands. But I want to put limits on it so the different columns expand to different maximum amounts.

What I have done here is used wxGlade to create a frame w/ a grid sizer that has 1 row and three columns. I want Part1 to have a fixed width of 'A', Part2 to have a fixed width of 'B' and Part3 to be able to expand as normal.

How do I do that?

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Tue May 24 11:35:21 2011

import wx

# begin wxGlade: extracode
# end wxGlade



class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        self.sizer_10_staticbox = wx.StaticBox(self.panel_1, -1, "Part2")
        self.sizer_11_staticbox = wx.StaticBox(self.panel_1, -1, "Part3")
        self.sizer_9_staticbox = wx.StaticBox(self.panel_1, -1, "Part1")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame1.__set_properties
        self.SetTitle("frame_2")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_4 = wx.GridSizer(1, 3, 0, 0)
        sizer_11 = wx.StaticBoxSizer(self.sizer_11_staticbox, wx.HORIZONTAL)
        sizer_10 = wx.StaticBoxSizer(self.sizer_10_staticbox, wx.HORIZONTAL)
        sizer_9 = wx.StaticBoxSizer(self.sizer_9_staticbox, wx.HORIZONTAL)
        grid_sizer_4.Add(sizer_9, 1, wx.EXPAND, 0)
        grid_sizer_4.Add(sizer_10, 1, wx.EXPAND, 0)
        grid_sizer_4.Add(sizer_11, 1, wx.EXPAND, 0)
        self.panel_1.SetSizer(grid_sizer_4)
        sizer_8.Add(self.panel_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_8)
        sizer_8.Fit(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame1


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_2 = MyFrame1(None, -1, "")
    app.SetTopWindow(frame_2)
    frame_2.Show()
    app.MainLoop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的影子我的梦 2024-11-16 21:42:28

如果您使用 GridSizer 我可能会建议您可以查看 GridBagSizer

一旦您决定它是否可用,那么您可能需要研究 sizer.AddGrowableRow(row)sizer.AddGrowableCol(col) 方法。它们允许您指示网格中展开的列或行。它们不像您熟悉的 BoxSizer 那样使用比例(因此,如果两列增长,它们都会以相同的速率增长),但您可以设置一些扩展,另一些不扩展。

索引是从零开始的,所以根据你的描述,我猜测类似 gridbagsizer_4.AddGrowableCol(2) 的东西,但就像我的评论所说,wxGlade 的命名约定让我感到不适,很难确定,并且这些方法在 GridSizer 上不可用。

对于任何感兴趣的各方,这里有一篇文章介绍了我的表单构建和表单对话框类: Form Builder 。将其发布到我可以包含附件的网站上比尝试将其全部粘贴到此处更容易。

If you're using a GridSizer I'd probably suggest you take a look at GridBagSizer instead.

Once you decide if that'll be usable, then you probably need to look into the sizer.AddGrowableRow(row) and sizer.AddGrowableCol(col) methods. They allow you to indicate columns or rows in the grid that expand. They don't use use proportions like you're familiar with from the BoxSizers (so if two columns grow they both grow at the same rate) but you can set some that expand and others that don't.

Indexes are zero based, so by your description I'd guess something like gridbagsizer_4.AddGrowableCol(2), but like my comment says, wxGlade's naming conventions make me ill and it's hard to tell for certain, and those methods won't be available on the GridSizer.

For any interested parties, there's a post covering my form building and form dialog classes available here: Form Builder. It was easier to post it on my site where I could include attachments than to try to paste it all here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文