不確定您的代碼無法正常工作的原因,似乎沒有明顯的錯誤。檢查這是否有效,並檢查您的代碼。
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()