Skip to content

Instantly share code, notes, and snippets.

@driscollis
Last active August 11, 2016 20:10
Show Gist options
  • Save driscollis/4e13762e22d01a9a2ee5b6d659b9547d to your computer and use it in GitHub Desktop.
Save driscollis/4e13762e22d01a9a2ee5b6d659b9547d to your computer and use it in GitHub Desktop.
Combo event example
import wx
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title='combo')
panel = wx.Panel(self)
choices = ['cat', 'dog', 'pig']
cbo = wx.ComboBox(panel, choices=choices)
cbo.Bind(wx.EVT_TEXT, self.onTextChange)
cbo.Bind(wx.EVT_COMBOBOX, self.onComboChange)
cbo.SetValue('random')
self.Show()
#----------------------------------------------------------------------
def onTextChange(self, event):
""""""
print 'text changed'
#----------------------------------------------------------------------
def onComboChange(self, event):
""""""
print 'combo changed'
if __name__ == '__main__':
app = wx.App(True)
frame = MyFrame()
app.MainLoop()
@SonOfLilit
Copy link

OK, seems like my issue is only when style includes wx.CB_READONLY.

This code only prints 0, not 1:

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='combo')
        panel = wx.Panel(self)

        choices = ['cat', 'dog', 'pig']
        cb0 = wx.ComboBox(panel, choices=choices)
        cb1 = wx.ComboBox(panel, choices=choices, style=wx.CB_READONLY)
        cb0.Bind(wx.EVT_TEXT, self.onTextChange0)
        cb1.Bind(wx.EVT_TEXT, self.onTextChange1)
        cb0.SetValue('dog')
        cb1.SetValue('dog')
        self.Show()

    def onTextChange0(self, event):
        print '0'

    def onTextChange1(self, event):
        print '1'

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment