Python Forum

Full Version: Dynamically Sized Widget
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
(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.
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