我正在学习wxPython库,现在我正在尝试使用wx.StaticBox
wx.StaticBoxSizer
。如文档https://wxpython.org/Phoenix/docs/html/wx.StaticBoxSizer.html#wx-staticboxsizer中所述,建议将元素添加到staticbox作为其子元素。而且我似乎就像文档中的示例一样,但结果是一堆叠加的元素,甚至没有静态框行。有什么问题,如何在wx.StaticBox
中进行正常布局?
这是初始化主框架的代码:
def Init_UI(self):
panel = wx.Panel(self)
sb = wx.StaticBox(panel, label='Personal Info')
sbs = wx.StaticBoxSizer(sb, wx.VERTICAL)
gender = wx.StaticText(sb, label='Your gender')
male = wx.RadioButton(sb, label='Male', style=wx.RB_GROUP)
female = wx.RadioButton(sb, label='Female')
sbs.AddMany([
(gender, ),
(male, ),
(female, ),
])
答案 0 :(得分:0)
您还没有set
面板的sizer,但请注意桌面的某些主题(至少在Linux上)不会显示静态框。因此,如果没有绘制框,请使用其他主题进行测试。 (首选项>外观)
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
panel = wx.Panel(self)
sb = wx.StaticBox(panel, -1, label='Personal Info')
sbs = wx.StaticBoxSizer(sb, wx.VERTICAL)
gender = wx.StaticText(sb, label='Your gender')
male = wx.RadioButton(sb, label='Male', style=wx.RB_GROUP)
female = wx.RadioButton(sb, label='Female')
sbs.AddMany([
(gender, ),
(male, ),
(female, ),
])
panel.SetSizer(sbs)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'A Static box')
frame.Show()
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()