| | |
Sizers Parent Child ...
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 32
Reputation:
Solved Threads: 0
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:
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!
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:
Python Syntax (Toggle Plain Text)
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!
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 6
The hierarchy ends up like this:
the loadBtn, transferBtn, inputArea, and transferArea objects are defined with:
the code right after that defines horizontalBox and adds loadBtn, transferBtn, and inputArea as it's children via the Add() method
Finally, you define verticalBox and make horizontalBox and transferArea its children through the same Add() method.
Python Syntax (Toggle Plain Text)
window background verticalBox horizontalBox inputArea transferBtn loadBtn transferArea
the loadBtn, transferBtn, inputArea, and transferArea objects are defined with:
Python Syntax (Toggle Plain Text)
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
Python Syntax (Toggle Plain Text)
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.
Python Syntax (Toggle Plain Text)
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)
Last edited by tyincali; Oct 28th, 2008 at 9:02 pm.
tyincali explained that very nicely.
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.
•
•
•
•
And is 'background.SetSizer(verticalBox)' saying verticalBox is parent of background?
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.
Last edited by vegaseat; Oct 29th, 2008 at 10:59 am.
May 'the Google' be with you!
![]() |
Other Threads in the Python Forum
- Previous Thread: Simple problem... please help!
- Next Thread: wxpython combining images with other things
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog data decimals dictionaries dictionary drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule script scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






