我正在创建一个ComboBox:
combo= ['a', 'b', 'c']
self.stm_checkpoint_drop=wx.ComboBox(self.panel, -1, value='Options', choices=combo)
self.stm_checkpoint_drop.Bind(wx.EVT_COMBOBOX, self.oncombo)
def oncombo(self,event):
selected = self.stm_checkpoint_drop.GetValue()
选定的变量仍为默认值“选项”。如何从存储在所选变量中的组合列表中选择值。
答案 0 :(得分:0)
不确定为什么你的代码不起作用,似乎没有明显的错误。检查这是否有效并检查您的代码。
import wx
class Myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.my_choices = ["Option A","Option B","Option C"]
self.panel = wx.Panel(self)
self.cbx = wx.ComboBox(self.panel, -1, value="Choose an Option", pos=(10,30), size=(300,30),choices=self.my_choices)
self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)
self.txt1 = wx.TextCtrl(self.panel, -1, "Selected Value", pos=(10,100), size=(300,30))
self.txt2 = wx.TextCtrl(self.panel, -1, "Selected Selection", pos=(10,130), size=(300,30))
self.txt3 = wx.TextCtrl(self.panel, -1, "Selected String", pos=(10,160), size=(300,30))
def on_selection(self, evt):
Choice = self.cbx.GetValue()
self.txt1.SetValue(Choice)
Choice = self.cbx.GetSelection()
self.txt2.SetValue(str(Choice))
Choice = self.cbx.GetStringSelection()
self.txt3.SetValue(Choice)
if __name__ == "__main__":
App = wx.App()
Myframe().Show()
App.MainLoop()