我对wxpython感到沮丧。我一直在尝试使用wx.lib.masked中的掩码ComboBox,但每当我尝试将其返回值与字符串进行比较时,结果始终为False,即使该字符串与ComboBox的返回值相同。使用通常的ComboBox,一切都按预期工作。那么,屏蔽的ComboBox有什么问题?
这是一段测试代码:
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 :(得分:0)
不同之处在于蒙面组合正在返回:
'one '
请注意,它不是'one',而是'one',后面有一堆空格。
只需在通话结束时添加.strip():
self.combo_box_masked.GetValue().strip()
这将解决它。