Frage

I notice that wxGlade (gui builder for wxPython) is enforcing a sizer as the first child element for wx.Frame which seems odd to me since almost every book and tutorial out there suggests to use a wx.Panel as the first child element.

So if I want to have a wx.Panel as the base for my gui (for example to have a consistent default background color on Windows) I have to go:

wx.Frame -> Sizer (1,1) -> wx.Panel -> Sizer (x,x) -> Content

instead of

wx.Frame -> wx.Panel -> Content

Out of curiosity can somebody explain this design decision to me?

War es hilfreich?

Lösung

According to Robin Dunn, creator of wxPython:

Personally I've been doing frame-sizer-panel-sizer lately because then frame.Fit() will let the sizer calculate the min size needed instead of just using the panel's current size. But if you don't use Fit or similar and there is only one child of the frame then there probably isn't any other reason to need a sizer on the frame as the frame will automatically fit the panel to the frame's client area. - https://groups.google.com/forum/#!searchin/wxpython-users/frame$20sizer$20panel/wxpython-users/nW5NivkfU7M/-1ISbrYvvjYJ

Another handy reason to use frame -> sizer -> panel is that it makes switching panels easier in that you can hide a panel and show another. See this tutorial for more information.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top