wxGTK + wxComboBox取消选择

时间:2013-11-04 20:36:44

标签: python gtk wxpython wxwidgets

在Windows下创建wx.ComboBox时,您可以指定wxCB_READONLY以允许用户从提议的选项中进行选择。但您可以清除选择:

combo.SetSelection(wx.NOT_FOUND)

但是在linux(wxGTK)下,该选项在创建时被取消选择,但一旦被选中就无法清除。不是以下任何一种:

combo.SetSelection(wx.NOT_FOUND)
combo.SetValue('')

无论如何都可以这样做吗?

1 个答案:

答案 0 :(得分:0)

实际上,将值设置为空字符串适用于Arch Linux:

import wx

########################################################################
class MyPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        choices = ["", "1", "2", "3"]
        self.choices = choices
        self.cbo = wx.ComboBox(self, value="1", choices=choices)
        btn = wx.Button(self, label="Reset")
        btn.Bind(wx.EVT_BUTTON, self.onReset)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.cbo, 0, wx.ALL, 5)
        sizer.Add(btn, 0, wx.ALL, 5)
        self.SetSizer(sizer)

    #----------------------------------------------------------------------
    def onReset(self, event):
        """"""
        print "resetting"
        self.cbo.SetValue("")


########################################################################
class MyFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="CombBox")
        panel = MyPanel(self)
        self.Show()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()