我正在尝试创建具有不同选择列表的wx.CheckListBox
两项。
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(256, 256))
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.HORIZONTAL)
choices_one = ['a', 'b', 'c']
choices_two = ['d', 'e', 'f', 'g']
check_list_box_one = wx.CheckListBox(self, wx.EXPAND | wx.ALL, choices=[])
check_list_box_two = wx.CheckListBox(self, wx.EXPAND | wx.ALL, choices=[])
check_list_box_one.Set(choices_one)
check_list_box_two.Set(choices_two)
sizer.Add(check_list_box_one)
sizer.Add(check_list_box_two)
panel.SetSizerAndFit(sizer)
self.Show()
app = wx.App()
MyFrame(None, -1, 'Test')
app.MainLoop()
我期望两个
CheckListBox
具有不同的条目('a','b','c')和('d','e','f','g')。但是第二个框显示为扩展为四个项目(作为choice_two
列表中的项目数)字段,具有来自choice_one
列表的值。 最佳答案
我强烈建议您使用WxGlade设计器:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((276, 297))
self.check_list_box_1 = wx.CheckListBox(self, wx.ID_ANY, choices=["choice 1", "choice 2", "choice 3"])
self.check_list_box_2 = wx.CheckListBox(self, wx.ID_ANY, choices=["choice 1", "choice 2", "choice 3"])
self.__set_properties()
self.__do_layout()
def __set_properties(self):
self.SetTitle("mainFrame")
def __do_layout(self):
mainSizer = wx.FlexGridSizer(1, 2, 0, 0)
mainSizer.Add(self.check_list_box_1, 0, 0, 0)
mainSizer.Add(self.check_list_box_2, 0, 0, 0)
self.SetSizer(mainSizer)
self.Layout()
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()