Reputation: 718
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
Upvotes: 0
Views: 1655
Reputation: 2179
If you haven't or can't adjust the initialization code to save the sizer at the time of creation, you can change the label starting with an object within the sizer.
If self.object
is an item within the sizer (such as a label or button or whatever):
self.object.GetContainingSizer().GetStaticBox().SetLabel("New Label")
This can be useful in particular because wxFormBuilder does not save a reference to the StaticBoxSizer
object or the StaticBox
within it.
Upvotes: 0
Reputation: 26767
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:
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(self.my_box)
# then do something like this later
self.my_box.SetLabel("I hate spam!")
Upvotes: 5