WXPYTHON:如何调整包含顶层框架中按钮的面板的分割窗口

时间:2015-09-12 14:13:42

标签: python wxpython

我有一个拆分器窗口,其中包含一个带有两个按钮的wx面板

1。 BUTTON1
2. button2

拆分器小部件似乎与其子项一起修复

enter image description here

这些是我的wx.frame代码

class MyFrame(wx.Frame):
    def __init__(self,title, pos, size):
        wx.Frame.__init__(self, None, -1, title, pos, size)
        self.MainSizer=wx.GridBagSizer(4,4)    self.search_pane_splitter=wx.SplitterWindow(self,style=wx.SP_NOBORDER,name="splitterWindow")
        self.search_pane_panel=wx.Panel(self.search_pane_splitter,size=(500,500),style=wx.SUNKEN_BORDER)
        r=wx.Button(self.search_pane_panel,label="button1")
        x=wx.Button(self.search_pane_panel,label="button2")
        self.MainSizer.Add(r,pos=(1,1),span=(1,1),flag=wx.EXPAND)
        self.MainSizer.Add(x,pos=(5,5),span=(2,2),flag=wx.EXPAND)
        self.MainSizer.AddGrowableCol(10)
        self.MainSizer.AddGrowableCol(1)
        self.MainSizer.AddGrowableRow(10)
        self.MainSizer.AddGrowableRow(7)
        self.search_pane_panel.SetSizer(self.MainSizer)

当我更改顶级框架的大小时,如何使拆分器窗口及其所有子元素增长?

如果无法做到这一点,欢迎使用替代解决方案

1 个答案:

答案 0 :(得分:0)

这是经过修改的python演示,以便一切都在增长 每个项目都需要EXPAND标志,它的扩展程度根据您告诉SPAN的行数和列数而有所不同。在这里,我已经设定了一切成长。

#!/usr/bin/env python

"""
A simple test of the GridBagSizer

http://wiki.wxpython.org/index.cgi/WriteItYourself

"""

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition)

        Buttons = []
        for i in range(6):
            Buttons.append(wx.Button(self,-1, "Button %i"%(i)))

        sizer = wx.GridBagSizer(9, 9)
        sizer.Add(Buttons[0], (0, 0), (1,1), wx.EXPAND)
        sizer.Add(Buttons[1], (1, 1), (1,7), wx.EXPAND)
        sizer.Add(Buttons[2], (6, 6), (3,3), wx.EXPAND)
        sizer.Add(Buttons[3], (3, 0), (1,1), wx.EXPAND)
        sizer.Add(Buttons[4], (4, 0), (1,1), wx.EXPAND)
        sizer.Add(Buttons[5], (5, 0), (1,1), wx.EXPAND)

        sizer.AddGrowableRow(0)
        sizer.AddGrowableRow(1)
        sizer.AddGrowableRow(2)
        sizer.AddGrowableRow(3)
        sizer.AddGrowableRow(4)
        sizer.AddGrowableRow(5)
        sizer.AddGrowableRow(6)
        sizer.AddGrowableRow(7)
        sizer.AddGrowableRow(8)
        sizer.AddGrowableRow(9)
        sizer.AddGrowableCol(0)
        sizer.AddGrowableCol(1)
        sizer.AddGrowableCol(2)
        sizer.AddGrowableCol(3)
        sizer.AddGrowableCol(4)
        sizer.AddGrowableCol(5)
        sizer.AddGrowableCol(6)
        sizer.AddGrowableCol(7)
        sizer.AddGrowableCol(8)
        sizer.AddGrowableCol(9)

        self.SetSizerAndFit(sizer)
        self.Centre()


class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "wx.gridbagsizer.py")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()    

请注意,除了sizer.AddGrowableRow(0)之外,您还可以使用比例标记,例如sizer.AddGrowableRow(0,1),但事情开始变得怪异!
遗憾的是我无法找到sizer.AddGrowableRow(wx.ALL)变种,或许其他人可以帮助那里,因为它看起来很笨拙,宣布每一个。
在您的代码中,您已将网格大小调整器声明为4行和4列,但稍后您将可增长的行和列声明为4x4网格之外。实际上,您还声明x应位于(5,5) 它似乎并不关心,它只会推动项目,但后续指令被忽略,我知道它将允许你声明growablerows超出声明的网格范围,没有抱怨。