Python Forum
[WxPython] Dynamically Sized Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] Dynamically Sized Widget
#1
I have a wx.Dialog box. In that dialog, I have widgetA. WidgetA contains widgetB. WidgetB can change its size at runtime in response to user selections.

When widgetB gets larger, then widgetA, and the dialog box both need to adjust their layout/size to accomodate the larger widget. This page talks about doing this, and describes a few methods:

https://wiki.wxpython.org/WhenAndHowToCallLayout

The hierarchy is such that all panels and the dialog frame will need resizing, so I'm tempted to use one of the ideas from the page:

widget = self.widgetThatWasChanged
while widget.GetParent():
    widget = widget.GetParent()
    widget.Layout()
    widget.Fit()
    if widget.IsTopLevel():
        break
Is there any real downside to this since any fancy code would just be calling Layout() on all the parents anyway?
Reply
#2
Read about sizers: https://wxpython.org/Phoenix/docs/html/s...rview.html
Reply
#3
(Nov-12-2018, 12:42 AM)Larz60+ Wrote: Read about sizers: https://wxpython.org/Phoenix/docs/html/s...rview.html

Is there a particular section you had in mind? I'm using sizers for layout (i.e. no absolute positioning). Calling object.Layout() when a sizer is configured causes the sizer to do its thing with the new window boundaries (it appears so, anyways). Unless I'm missing something, I'm not aware of how sizers would automatically address container changes especially when windows are nested like nested panels in a custom widget.
Reply
#4
This snippet I posted some time ago embeds sizers. Hope you can make some sense out of it. Perhaps if you run it and try resizing it will make sense, my brain has difficulty remembering anything more that a month old (sorry about that I'm in my 70's, so it comes as baggage).

https://python-forum.io/Thread-Perfectly...n-template
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Dynamically Deleting Widget smabubakkar 1 3,354 Feb-15-2020, 11:11 PM
Last Post: Larz60+
  [PyQt] dynamically resize custom widget fill remaining space ironcthulhu 1 11,213 Dec-31-2019, 09:45 PM
Last Post: Denni
  [Tkinter] Text window not properly sized smabubakkar 1 1,891 Jun-16-2019, 08:55 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020