user1008537
user1008537

Reputation:

How to add widgets inside a StaticBox, wxPython?

it is possible to add things into a StaticBox, in wxPython? I know this is a rather simple question however I cannot seem to find anything on Google. I would like to actually be able to add things into the StaticBox, such as buttons.

Upvotes: 3

Views: 2158

Answers (1)

Bastien Léonard
Bastien Léonard

Reputation: 61713

Looking at the code from one of my old projects, it looks like I used a StaticBoxSizer, and added the elements to this sizer. Quick test:

app = wx.App(redirect=False)
frame = wx.Frame(None)
static_box = wx.StaticBox(frame, label='Label')
sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)

for i in range(5):
    sizer.Add(wx.Button(frame, label='Button ' + str(i)))

frame.Sizer = sizer
frame.Sizer.Fit(frame)
frame.Show()
app.MainLoop()

Upvotes: 2

Related Questions