tags:

views:

80

answers:

1

Hi,

Is there a way of modifying the label of a StaticBoxSizer on wxPython after initialization?

I couldn't find anything on wxPython's documentation.

Thank you

+3  A: 

When you create a wx.StaticBoxSizer, you must pass it a wx.StaticBox as the first argument of the initializer, this is what you need to modify to change the label. If you look at the class hierarchies, they go as follows:

  • object -> Object -> EvtHandler -> Window -> Control -> StaticBox
  • object -> Object -> Sizer -> BoxSizer -> StaticBoxSizer

As you may have figured out, SetLabel is not a method of the sizer or any of it's parents, it instead lives in the Control class, so the box inherits it.

# creating the static box sizer
self.my_box = wx.StaticBox(self.panel, wx.ID_ANY, "Spam, spam, spam")
self.sizer_static_box = wx.StaticBoxSizer(my_box)

# then do something like this later        
self.my_box.SetLabel("I hate spam!")
Nick T