简体   繁体   中英

WXPYTHON: How to resize a splitter window that contains a panel with buttons in a top level frame

I have a splitter window that contains a wx panel with two buttons

1. button1
2. button2

The splitter widget appears to be fixed along with its children

在此处输入图片说明

these are my wx.frame codes

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)

How can I make the splitter window and all of its children elements grow when I change the size of the top level frame?

If this can't be done, Alternative solutions are welcomed

Here is the python demo amended so that everything grows.
Each item requires the EXPAND Flag and how much it expands varies according to the number of rows and cols you have told it to SPAN. Here I have set everything to grow.

#!/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()    

Note that in addition to sizer.AddGrowableRow(0) you can also use the proportion flag, as in sizer.AddGrowableRow(0,1) but then things start to get freaky!
Seems a shame that I can't find a sizer.AddGrowableRow(wx.ALL) variant perhaps someone else can help there, as it looks ungainly, declaring each one.
In your code, you have declared the grid sizer to be 4 rows and 4 columns but later you declare the growable rows and columns to be outside of a 4x4 grid. Indeed, you also declare that x should be positioned at (5,5).
It just doesn't seem to care, it will just shove the item in but subsequent instructions are ignored, I do know that it will allow you to declare growablerows beyond the bounds of the grid as declared, without complaint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM