Sizers Parent Child ...
Greetings:
I am having trouble with reading the code in thread "Tutorial: GUI programming with wxPython" ( http://www.daniweb.com/forums/post623598-3.html )
Where tut shows code:
import wx
"""Example with sizers for dynamic resizing."""
app = wx.App(redirect=False)
window = wx.Frame(None, title = 'Sample GUI App',
pos = (100,100), size = (400,500))
background = wx.Panel(window)
loadBtn = wx.Button(background, label = 'Load')
transferBtn = wx.Button(background, label = 'Transfer')
inputArea = wx.TextCtrl(background)
transferArea = wx.TextCtrl(background, style = wx.TE_READONLY | wx.TE_MULTILINE)
horizontalBox = wx.BoxSizer()
horizontalBox.Add(inputArea, proportion = 1, border = 0)
horizontalBox.Add(transferBtn, proportion = 0, border = 0)
horizontalBox.Add(loadBtn, proportion = 0, border = 0)
verticalBox = wx.BoxSizer(wx.VERTICAL)
verticalBox.Add(horizontalBox, proportion = 0, flag = wx.EXPAND, border = 0)
verticalBox.Add(transferArea, proportion = 1, flag = wx.EXPAND, border = 0)
background.SetSizer(verticalBox)
window.Show()
app.MainLoop()
Guess my dyslexia is acting up:
It doesn't look like horizontalBox is the child of verticalBox.
"It looks like 'background' is the child of 'window' .
'loadBtn = wx.Button(background' = 'loadBtn' is the child of 'background' .
'horizontalBox.Add(inputArea' = 'horizontalBox' is the child of 'inputArea'
'verticalBox.Add(horizontalBox' = and 'verticalBox' is the child of 'horizontalBox' .
And is 'background.SetSizer(verticalBox)' saying verticalBox is parent of background?
Can someone straighten me out.
How do I properly read these statements.
Maybe if I knew the syntax of each statement.
Thanks!
vmars
Junior Poster in Training
54 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
tyincali explained that very nicely.
And is 'background.SetSizer(verticalBox)' saying verticalBox is parent of background?
You are simply setting the main sizer, background is still the parent. Remember that the first object inside the () is not necessarily the parent.
In your case only the widgets have a parent argument:
wx.Frame(parent, id, title, pos, size, style)
wx.Panel(parent, id, pos, size, style)
wx.Button(parent, id, label, pos, size, style)
wx.TextCtrl(parent, id, value, pos, size, style)
Method sizer.Add() has the following arguments:
sizer.Add(widget, proportion, flag, border)
A lot of the pos, size, style, border, flag arguments have defaults. When you use sizers you don't have to supply the position argument in most cases. It's the role of the sizer to put the widget in the correct position.
vegaseat
DaniWeb's Hypocrite
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416