1 回答
TA贡献2039条经验 获得超7个赞
keys如果字典中的 是字符串,那应该可以工作。
如果不是,您应该从以下位置收到错误:
choices=list(self.algorithms.keys())
choices应该list是strings
在这种情况下尝试:
choices=[str(k) for k in self.algorithms]
反而。
编辑风格wx.CB_READONLY
字符串必须在组合框选项列表中
这不是其他样式的情况
因此,如果将索引用于该选择,则必须小心
这是一些应该可以工作的简单代码:
import wx
class Myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.my_choices = {"Choose a sport":0,"Board Sports":1,"Ball Sports":2,"Fight Sports":3}
#self.my_choices = ["Board Sports","Ball Sports","Fight Sports"]
self.my_subchoices = [[],["Skate boarding","Surfing","Ski boarding"],["Football","Cricket","Rugby"],["Boxing","Wrestling","Karate"]]
pan = wx.Panel(self)
self.cbx = wx.ComboBox(pan, -1, value = "Choose a sport", pos=(10,30), size=(300,30),choices=list(self.my_choices),style=wx.CB_DROPDOWN | wx.CB_READONLY )
self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)
def on_selection(self, evt):
Choice = self.cbx.GetSelection()
msg = ""
#
# Ignore choice 0 because of style wx.CB_READONLY or include a blank entry
# for choice 0 in my_subchoices
for x in self.my_subchoices[Choice]:
msg += x+"\n"
self.cbx.SetToolTip(msg)
if __name__ == "__main__":
App = wx.App()
Myframe().Show()
App.MainLoop()
添加回答
举报