Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

python - 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()
question from:https://stackoverflow.com/questions/65903201/how-do-i-resize-a-widget-in-wxpython-using-gridsizer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this

def OnResize(self,event):
    FrameSize = self.GetSize()
    widthA,heightA = FrameSize[0],FrameSize[1]
    self.folder_tree_project.SetSize((int(widthA*0.3),int(heightA*0.75)))
    self.Sizer.Layout()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...