需要使用数百个选项填充wx.Choice
,看起来只有一种方法,即Append()
:
choiceBox = wx.Choice(choices=[], id = wx.ID_ANY, parent=self, pos=wx.Point(0, 289),
size=wx.Size(190, 21), style=0)
for item in aList:
choiceBox.Append(item)
我试图一次性附加一份完整的清单,但它不会起作用,那么还有更好的方法吗?
答案 0 :(得分:4)
什么???你只是给它选择
choiceBox = wx.Choice(choices=aList, id = wx.ID_ANY, parent=self, pos=wx.Point(0, 289),
size=wx.Size(190, 21), style=0)
您也可以稍后使用
执行此操作choicebox.SetItems(aList)
这是一个简单的例子,其中生成选项需要很长时间,但我们使用线程来阻止ui
import wx
import threading
import time
import random
def make_choices():
choices = []
for _ in range(80):
choices.append(str(random.randint(0,1000000)))
time.sleep(0.1)
print "Making choice List!"
return choices
def make_choice_thread(wxChoice,choice_fn):
wx.CallAfter(wxChoice.SetItems,choice_fn())
wx.CallAfter(wxChoice.SetSelection,0)
a = wx.App(redirect=False)
fr = wx.Frame(None,-1,"A Big Choice...")
st = wx.StaticText(fr,-1,"For Some reason you must pick from a large list")
ch = wx.Choice(fr,-1,choices=["Loading...please wait!"],size=(200,-1),pos=(15,15))
ch.SetSelection(0)
t = threading.Thread(target=make_choice_thread,args=(ch,make_choices))
t.start()
fr.Show()
a.MainLoop()