2013-07-13 18 views
0

我有一個wxpython令人沮喪的問題。我一直在嘗試使用wx.lib.masked中的掩碼組合框,但每當我嘗試將其返回值與一個字符串比較時,結果始終爲False,即使該字符串與ComboBox中的返回值相同。使用通常的ComboBox,一切都按預期工作。那麼,蒙板組合框有什麼問題?wxpython返回類型的蒙面組合

這裏有一段測試代碼:

import wx 
import wx.lib.masked as masked 

class TestMasked(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent, id=wx.ID_ANY) 
     choices = ['one', 'two', 'three'] 
     self.combo_box_masked = masked.Ctrl(self, -1, 
           controlType = masked.controlTypes.COMBO, 
           choices = choices, 
           autoSelect=True 
          ) 
     self.combo_box_masked.SetCtrlParameters(formatcodes = 'F!V_') 
     self.Bind(wx.EVT_COMBOBOX, self.EvtComboMasked, self.combo_box_masked) 
     self.combo_box = wx.ComboBox(self, wx.ID_ANY, choices=choices) 
     self.Bind(wx.EVT_COMBOBOX, self.EvtCombo, self.combo_box) 
     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(self.combo_box_masked, 1, wx.ALL, 5) 
     sizer.Add(self.combo_box, 1, wx.ALL, 5) 
     self.SetSizerAndFit(sizer) 

    def EvtCombo(self, event): 
     one_combo = self.combo_box.GetValue() 
     one_str = 'one' 
     print one_combo == one_str 

    def EvtComboMasked(self, event): 
     one_combo = self.combo_box_masked.GetValue() 
     one_str = 'one' 
     print one_combo == one_str 

class DemoFrame(wx.Frame): 
    def __init__(self): 
     wx.Frame.__init__(self, None, wx.ID_ANY, "Test Masked") 
     panel = TestMasked(self) 
     self.SetSize((500,500)) 
     self.Center() 
     self.Show() 

#---------------------------------------------------------------------- 
if __name__ == "__main__": 
    app = wx.PySimpleApp() 
    frame = DemoFrame() 
    app.MainLoop() 

回答

0

不同的是,蒙面組合將返回此:

'one   ' 

請注意,這不是「一」,但「一」用之後的一堆空間。

只是.strip()添加到通話結束:

self.combo_box_masked.GetValue().strip() 

這將解決這個問題。

+0

是的,你是對的。謝謝。對不起,花了這麼長的時間來回答。我剛看到你的答案。我想我錯過了關於你的回覆的電子郵件。 – Sohos