TextCtrl eating all events when empty in MS Windows

Sid Wiesner sid at seegrid.com
Thu Mar 1 11:47:14 PST 2007


Robin Dunn wrote:
> Please create a small runnable sample that shows the problem so we can 
> see exactly what you are trying to do.
> 
> http://wiki.wxpython.org/index.cgi/MakingSampleApps
> 

Okay, here is an example. If you run it, it will just show a text 
control. On Mac OS X, if the control is empty and you press backspace 
or any other keys, events are generated. On Windows, if it is empty 
and keys are pressed (other than normal ASCII keys), no events are 
generated. Any ideas?

#!/usr/bin/env python

import wx

class Frame(wx.Frame):

     def __init__(self, parent, id):
         wx.Frame.__init__(self, parent, id, 'Broken on windows')
         panel = wx.Panel(self)
         textCtrl = wx.TextCtrl(panel, wx.NewId(), "")

         self.Bind(wx.EVT_CHAR, self.onKeyPress)
         self.Bind(wx.EVT_TEXT, self.onTextCtrlChange)

     def onKeyPress(self, event):
         print "key press:", event.GetKeyCode()

     def onTextCtrlChange(self, event):
         print "text change:", event.GetString()

if __name__ == '__main__':
     app = wx.PySimpleApp()
     frame = Frame(parent=None, id=-1)
     frame.Show()
     app.MainLoop()





More information about the wxpython-users mailing list