Hi Simson,
Mike
1. Thanks for posting this. I didn't post code because, well, I forgot. Thanks for posting the example.
No problem.
I'm a bit new to wxpython.
Welcome to the world of wxPython! It's fun, if a bit confusing at first...
2. My error is that I was calling Fit() and not Layout(). Duh.
Layout() basically forces the sizers to recalculate the widgets placements and such and I think it may call Refresh when it's done, although I am not sure. As I understand it, Fit() usually justs "fits" the widgets to the smallest area it can inside of the parent (a wx.Frame or wx.Panel).
3. I remain confused by the inconsistent use of accessor methods for properties.
Some properties are set and get with SetProperty() and GetProperty() while others are set with just Property() while still others are get with just Property().
For example, wx.Control uses SetLabel() to set the label and GetLabelText() to get it.
What's the difference between a Label and a LabelText?
But that same control uses GetAlignment() to get the alignment and doesn't seem to have any means to set the Alignment after-the-fact. (or am I missing it?)
This gets confusing because there is a lot of inheritance hoodoo going on here. Most of the widgets inherit properties from another class, so the docs usually only show the new methods of the widget and not the methods from that which it inherits from, unless said widget is overriding the inherited method. I usually find that it's faster to just use Python's builtin introspection tools to find out the methods of my widgets. Do something like this:
myWidget = wx.SomeWidget()
print dir(myWidget)
or
import wx
print dir(wx.StaticText)
In the latter case, you would get something like this:
['AcceleratorTable', 'AcceptsFocus', 'AcceptsFocusFromKeyboard', 'AddChild', 'AddPendingEvent', 'AdjustForLayoutDirection', 'Alignment', 'AssociateHandle', 'AutoLayout', 'BackgroundColour', 'BackgroundStyle', 'BestSize', 'BestVirtualSize', 'Bind', 'Border', 'CacheBestSize', 'CanSetTransparent', 'CaptureMouse', 'Caret', 'Center', 'CenterOnParent', 'Centre', 'CentreOnParent', 'CharHeight', 'CharWidth', 'Children', 'ClassName', 'ClearBackground', 'ClientAreaOrigin', 'ClientRect', 'ClientSize', 'ClientToScreen', 'ClientToScreenXY', 'ClientToWindowSize', 'Close', 'Command', 'Connect', 'Constraints', 'ContainingSizer', 'ConvertDialogPointToPixels', 'ConvertDialogSizeToPixels', 'ConvertPixelPointToDialog', 'ConvertPixelSizeToDialog', 'Create', 'Cursor', 'DLG_PNT', 'DLG_SZE', 'DefaultAttributes', 'Destroy', 'DestroyChildren', 'Disable', 'Disconnect', 'DissociateHandle', 'DragAcceptFiles', 'DropTarget', 'EffectiveMinSize', 'Enable', 'Enabled', 'EventHandler', 'EvtHandlerEnabled', 'ExtraStyle', 'FindFocus', 'FindWindowById', 'FindWindowByLabel', 'FindWindowByName', 'Fit', 'FitInside', 'Font', 'ForegroundColour', 'Freeze', 'GetAcceleratorTable', 'GetAdjustedBestSize', 'GetAlignment', 'GetAutoLayout', 'GetBackgroundColour', 'GetBackgroundStyle', 'GetBestFittingSize', 'GetBestSize', 'GetBestSizeTuple', 'GetBestVirtualSize', 'GetBorder', 'GetCapture', 'GetCaret', 'GetCharHeight', 'GetCharWidth', 'GetChildren', 'GetClassDefaultAttributes', 'GetClassName', 'GetClientAreaOrigin', 'GetClientRect', 'GetClientSize', 'GetClientSizeTuple', 'GetConstraints', 'GetContainingSizer', 'GetCursor', 'GetDefaultAttributes', 'GetDropTarget', 'GetEffectiveMinSize', 'GetEventHandler', 'GetEvtHandlerEnabled', 'GetExtraStyle', 'GetFont', 'GetForegroundColour', 'GetFullTextExtent', 'GetGrandParent', 'GetGtkWidget', 'GetHandle', 'GetHelpText', 'GetHelpTextAtPoint', 'GetId', 'GetLabel', 'GetLabelText', 'GetLayoutDirection', 'GetMaxHeight', 'GetMaxSize', 'GetMaxWidth', 'GetMinHeight', 'GetMinSize', 'GetMinWidth', 'GetName', 'GetNextHandler', 'GetParent', 'GetPosition', 'GetPositionTuple', 'GetPreviousHandler', 'GetRect', 'GetScreenPosition', 'GetScreenPositionTuple', 'GetScreenRect', 'GetScrollPos', 'GetScrollRange', 'GetScrollThumb', 'GetSize', 'GetSizeTuple', 'GetSizer', 'GetTextExtent', 'GetThemeEnabled', 'GetToolTip', 'GetTopLevelParent', 'GetUpdateClientRect', 'GetUpdateRegion', 'GetValidator', 'GetVirtualSize', 'GetVirtualSizeTuple', 'GetWindowBorderSize', 'GetWindowStyle', 'GetWindowStyleFlag', 'GetWindowVariant', 'GrandParent', 'GtkWidget', 'Handle', 'HasCapture', 'HasFlag', 'HasMultiplePages', 'HasScrollbar', 'HasTransparentBackground', 'HelpText', 'Hide', 'HitTest', 'HitTestXY', 'Id', 'InheritAttributes', 'InheritsBackgroundColour', 'InitDialog', 'InvalidateBestSize', 'IsBeingDeleted', 'IsDoubleBuffered', 'IsEnabled', 'IsExposed', 'IsExposedPoint', 'IsExposedRect', 'IsFrozen', 'IsRetained', 'IsSameAs', 'IsShown', 'IsShownOnScreen', 'IsTopLevel', 'Label', 'LabelText', 'Layout', 'LayoutDirection', 'LineDown', 'LineUp', 'Lower', 'MakeModal', 'MaxHeight', 'MaxSize', 'MaxWidth', 'MinHeight', 'MinSize', 'MinWidth', 'Move', 'MoveAfterInTabOrder', 'MoveBeforeInTabOrder', 'MoveXY', 'Name', 'Navigate', 'NewControlId', 'NextControlId', 'NextHandler', 'OnPaint', 'PageDown', 'PageUp', 'Parent', 'PopEventHandler', 'PopupMenu', 'PopupMenuXY', 'Position', 'PostCreate', 'PrepareDC', 'PrevControlId', 'PreviousHandler', 'ProcessEvent', 'ProcessPendingEvents', 'PushEventHandler', 'Raise', 'Rect', 'Refresh', 'RefreshRect', 'RegisterHotKey', 'ReleaseMouse', 'RemoveChild', 'RemoveEventHandler', 'Reparent', 'ScreenPosition', 'ScreenRect', 'ScreenToClient', 'ScreenToClientXY', 'ScrollLines', 'ScrollPages', 'ScrollWindow', 'SendSizeEvent', 'SetAcceleratorTable', 'SetAutoLayout', 'SetBackgroundColour', 'SetBackgroundStyle', 'SetBestFittingSize', 'SetCaret', 'SetClientRect', 'SetClientSize', 'SetClientSizeWH', 'SetConstraints', 'SetContainingSizer', 'SetCursor', 'SetDimensions', 'SetDoubleBuffered', 'SetDropTarget', 'SetEventHandler', 'SetEvtHandlerEnabled', 'SetExtraStyle', 'SetFocus', 'SetFocusFromKbd', 'SetFont', 'SetForegroundColour', 'SetHelpText', 'SetHelpTextForId', 'SetId', 'SetInitialSize', 'SetLabel', 'SetLayoutDirection', 'SetMaxSize', 'SetMinSize', 'SetName', 'SetNextHandler', 'SetOwnBackgroundColour', 'SetOwnFont', 'SetOwnForegroundColour', 'SetPosition', 'SetPreviousHandler', 'SetRect', 'SetScrollPos', 'SetScrollbar', 'SetSize', 'SetSizeHints', 'SetSizeHintsSz', 'SetSizeWH', 'SetSizer', 'SetSizerAndFit', 'SetThemeEnabled', 'SetToolTip', 'SetToolTipString', 'SetTransparent', 'SetValidator', 'SetVirtualSize', 'SetVirtualSizeHints', 'SetVirtualSizeHintsSz', 'SetVirtualSizeWH', 'SetWindowStyle', 'SetWindowStyleFlag', 'SetWindowVariant', 'ShouldInheritColours', 'Show', 'Shown', 'Size', 'Sizer', 'Thaw', 'ThemeEnabled', 'ToggleWindowStyle', 'ToolTip', 'TopLevel', 'TopLevelParent', 'TransferDataFromWindow', 'TransferDataToWindow', 'Unbind', 'UnregisterHotKey', 'Update', 'UpdateClientRect', 'UpdateRegion', 'UpdateWindowUI', 'UseBgCol', 'Validate', 'Validator', 'VirtualSize', 'WarpPointer', 'WindowStyle', 'WindowStyleFlag', 'WindowToClientSize', 'WindowVariant', 'Wrap', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_setOORInfo', 'thisown']
Yes, that simple widget is, in fact, quite complicated. I personally recommend getting Robin Dunn's "wxPython in Action" book. It talks about most of the common widgets and lists their methods.
4. Where is the right place to find out about all the methods? On the web page:
wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
This is the official docs (man pages) that are generated from source (I think). There's also this set which has been tweaked some by Andrea Gavana: http://xoomer.alice.it/infinity77/wxPython/
It sounds like there will be another set of docs to be released sooner or later...
There is mention of GetLabelText() but no mention of SetLabel().
It turns out that SetLabel() is described on the wx.Window web page. Which seems really weird, since wx.Window objects don't show labels.
Thanks!
Not sure why that's there...but I think the control inherits that method from wx.Window.
Mike