[wxPython] layout manager?

Robert Amesz rcameszREMOVETHIS at dds.removethistoo.nl
Mon Jun 11 19:03:27 EDT 2001


Brian Lee wrote:

> Hi? I'm a newbie at wxPython and this is wxPython specific question.
> 
> Is there any examples of controlling window layout in wxPython? I
> read some docs on http://wxpython.org/ but I don't understand it.
> And the short examples in the docs do not work.

The docs are for C++, and are not 100% accurate for wxPython. 
Specifically. for wxLayoutContraints I've noticed that

  "Most constraints are initially set to have the relationship
   wxUnconstrained, which means that their values should be
   calculated by looking at known constraints. The exceptions are
   width and height, which are set to wxAsIs to ensure that if the
   user does not specify a constraint, the existing width and height
   will be used, to be compatible with panel items which often have
   take a default size."

is wrong: you need to set the constraints for width and height 
explicitly to wxAsIs. The wxPython demo is a more reliable source of 
information and code snippets.


> What I actually want is to control size of component in a window. If
> user resize the window, the component in the window should be
> resized. I think setting a static value for position and size is not
> good for my program.

Look for wxBoxSizer or wxLayoutConstraints or LayoutAnchor in the 
documentation. Also check the demo: there are examples to be found in 
the 'Windows Layout' section.

WxLayoutConstraints is the most flexible of the layout managers, 
wxBoxSizers is fine if you simply want a row or column of things. The 
one trick wxBoxSizers can do which WxLayoutConstraints lacks is the 
ability to fix the aspect ratio of a resizable subwindow.

Keep in mind that layout managers can be used on multiple levels: you 
can use wxPanels within wxPanels (or wxFrames) and use autolayout on 
each of those. Using subpanels can make life a lot easier, and has the 
added advantage of making your code less cluttered, as each wxPanel 
only needs to handle those events coming from or addressed to the 
subwindows or controls on that particular panel.


Robert Amesz



More information about the Python-list mailing list