我对 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()