Skip to content
Advertisement

How do i resize a widget in WxPython using GridSizer

Introduction and Issue

I’ve made a gridsizer to resize my frame itself.

But because of the gridsizer if I use WX_EXPAND flag (to let them have a new height and width when I use self.Layout() to refresh when the app is resized) they don’t resize the % of the screen I gave them (I put blank widget to put all my widget where I want).

Example here

What I have tried

I’ve tried to make a wx.GridBagSizer but I can’t understand why it always say that GenericTreeCtrl don’t exist (its a must I need this tree) so I’m asking a way to do this with wx.GridSizer.

I want to work with something like that and be able to resize my widget: what I want to be resizable

Question

Can you please tell me whats the correct and optimal way to dynamically resize a widget using a wx.GridSizer?

class mainPanel(wx.Panel):
def __init__(self, parent, pageNum, FrameSize):
    self.parent = parent
    self.pageNum = pageNum
    wx.Panel.__init__(self, parent=parent)
    Sizer = wx.GridSizer(6,6,0,0)
    self.PathList = []
    self.PathSelected = []
    self.pastePath = ""
    self.SetSizer(Sizer)


    #tree
    widthA,heightA = FrameSize[0],FrameSize[1]
    path = "/media/" + os.getlogin()
    self.folder_tree_project = wx.GenericDirCtrl(self, wx.ID_ANY,path, (0,0), wx.Size(widthA*0.3,heightA*0.75),wx.FULL_REPAINT_ON_RESIZE|wx.DIRCTRL_MULTIPLE)
    Sizer.Add(self.folder_tree_project,0,wx.LEFT,0)
    self.t1 = self.folder_tree_project.GetTreeCtrl()
    self.folder_tree_project.ShowHidden(False)
    self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelect,id=self.t1.GetId())

    self.Bind(wx.EVT_SIZE, self.OnResize)

    #--------------------------------------------------------
    
def OnResize(self,event):
    FrameSize = self.GetSize()
    self.Sizer.Layout()

Advertisement

Answer

I will not be able to test it Leonardo but thanks for the reply ! (i did not answered because of the Global Game Jam that i was participating) I’ve found another way thanks to someone on another forum, using the app ‘WxGlade’ I was able to understand how GridBagSizer work. You can’t do things like GenericDirCtrl in WxGlade but I’ve read the code given by it by putting button and blank text like I want and putting gridbagsizer, with the previsualization and the generated code I was able to understand how GridBagSizer work.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement