Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created August 26, 2014 18:06
Show Gist options
  • Save driscollis/69b83f6b1a53f533eeb6 to your computer and use it in GitHub Desktop.
Save driscollis/69b83f6b1a53f533eeb6 to your computer and use it in GitHub Desktop.
wxPython multiple events on the same handler
import wx
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(500,500))
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
text = wx.TextCtrl(panel)
text.SetFocus()
text.Bind(wx.EVT_TEXT, self.onKey)
text.Bind(wx.EVT_KEY_DOWN, self.onKey)
#----------------------------------------------------------------------
def onKey(self, event):
""""""
if hasattr(event, "GetKeyCode"):
print "event fired by EVT_KEY_DOWN"
else:
print "event fired by EVT_TEXT"
event.Skip()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment