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!

The hierarchy ends up like this:

window
	background
		verticalBox
			horizontalBox
				inputArea
				transferBtn
				loadBtn
			transferArea

the loadBtn, transferBtn, inputArea, and transferArea objects are defined with:

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)

the code right after that defines horizontalBox and adds loadBtn, transferBtn, and inputArea as it's children via the Add() method

horizontalBox = wx.BoxSizer()
horizontalBox.Add(inputArea, proportion = 1, border = 0)
horizontalBox.Add(transferBtn, proportion = 0, border = 0)
horizontalBox.Add(loadBtn, proportion = 0, border = 0)

Finally, you define verticalBox and make horizontalBox and transferArea its children through the same Add() method.

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)
commented: Thanks for helping out! +10

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.