代码演示
import wx
class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(parent=None, title="列表选择")
# 定义一个列表
self.list = ["a", "b", "c", "d"]
# 创建一个列表的选择框
self.listbox = wx.ListBox(frame, -1, pos=(10, 10), size=(300, 120), choices=self.list, style=wx.LB_SINGLE)
# 绑定列表选择事件
self.Bind(wx.EVT_LISTBOX, self.select_list, self.listbox)
frame.Show()
return True
def select_list(self, event):
index = event.GetEventObject().GetSelection() # 获取索引
print(self.list[index]) # 打印选择的list
app = MyApp()
app.MainLoop()