wxPython: Items in BoxSizer don't expand horizontally, only vertically

前端 未结 1 936
日久生厌
日久生厌 2020-12-29 11:36

I have several buttons in various sizers and they expand in the way that I want them to. However, when I add the parent to a new wx.BoxSizer that is used to add a border aro

相关标签:
1条回答
  • 2020-12-29 12:08

    First of all, you're passing some flags incorrectly. BoxSizer takes wx.HORIZONTAL or wx.VERTICAL, not wx.EXPAND. sizer.Add does not take wx.HORIZONTAL.

    If you have a VERTICAL BoxSizer, wx.EXPAND will make the control fill horizontally, while a proportion of 1 or more (second argument to Add) will make the control fill vertically. It's the opposite for HORIZONTAL BoxSizers.

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(widget1, 0, wx.EXPAND)
    sizer.Add(widget2, 1)
    

    widget1 will expand horizontally. widget2 will expand vertically.

    If you put a sizer in another sizer, you need to be sure to have its proportion and EXPAND flags set so that its insides will grow how you want them to.

    I'll leave the rest to you.

    0 讨论(0)
提交回复
热议问题