2017-06-13 38 views
0

我創建一個組合框爲:組合框的值不會更新在事件的wxPython

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

不確定您的代碼無法正常工作的原因,似乎沒有明顯的錯誤。檢查這是否有效,並檢查您的代碼。

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() 
相關問題