Having trouble binding EVT_CHAR in a text control to an event handler

Try ammending your sample to read:
self.tc1 = wx.TextCtrl(self)
self…Bind(wx.EVT_CHAR, self.OnEntryKeypress)
matrix.Add(self.tc1, wx.EXPAND)
I would also suggest you take a look at the validator sample in the
documents and samples package.
Gadget/Steve

···

On 10/10/2012 6:54 PM, Robert wrote:

Hi!

  I'm new to wxpython, and I can't figure out what I'm doing

wrong… I’ve looked at other samples of event handlers and I
don’t know why this isn’t working.

  I'm working on a sudoku GUI, and I'm setting it up as 9 3x3

gridsizers within a larger gridsizer. Each box in the sudoku
matrix consists of two text controls, a narrow one on top for
notes and a large one below for solved values. I’m trying to make
it so that you can only enter numbers in the text controls and so
that you can only enter one number in the larger text controls. I
figured I would do this with EVT_CHAR handlers.

  From the other sample code, I think i'm supposed to write

self.Bind(wx.EVT_CHAR, self.OnKeyPress, tcl), with tcl being the
name of the text control for which i want to bind EVT_CHAR events
to my OnKeyPress method. However, this doesn’t seem to be doing
anything. I reduced the matrix to a single text ctrl to test the
handler, and I wrote a logger too, and I think my event handler is
just wrong. I suspect the problem is in the third parameter of my
self.Bind function. If you can spot what’s wrong, or clear up some
misconception I must have about .Bind(), that would be awesome.
Code is attached.

  Thanks,

  -Rob

  --

  To unsubscribe, send email to

or visit

tc1

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

And I suggest looking at one of several wxPython Sudoku programs that Google could point you to that do it without using sizers and text controls but rather draw the numbers on a single window themselves. Then you don't have to worry about focus issues, having the overhead of dozens of widgets, etc.

···

On 10/10/12 12:24 PM, Gadget/Steve wrote:

On 10/10/2012 6:54 PM, Robert wrote:

Hi!

I'm new to wxpython, and I can't figure out what I'm doing wrong...
I've looked at other samples of event handlers and I don't know why
this isn't working.

I'm working on a sudoku GUI, and I'm setting it up as 9 3x3 gridsizers
within a larger gridsizer. Each box in the sudoku matrix consists of
two text controls, a narrow one on top for notes and a large one below
for solved values. I'm trying to make it so that you can only enter
numbers in the text controls and so that you can only enter one number
in the larger text controls. I figured I would do this with EVT_CHAR
handlers.

From the other sample code, I think i'm supposed to write
self.Bind(wx.EVT_CHAR, self.OnKeyPress, tcl), with tcl being the name
of the text control for which i want to bind EVT_CHAR events to my
OnKeyPress method. However, this doesn't seem to be doing anything. I
reduced the matrix to a single text ctrl to test the handler, and I
wrote a logger too, and I think my event handler is just wrong. I
suspect the problem is in the third parameter of my self.Bind
function. If you can spot what's wrong, or clear up some misconception
I must have about .Bind(), that would be awesome. Code is attached.

Thanks,
-Rob
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Try ammending your sample to read:

         self.tc1 = wx.TextCtrl(self)
         self.*tc1*.Bind(wx.EVT_CHAR, self.OnEntryKeypress)
         matrix.Add(self.tc1, wx.EXPAND)

I would also suggest you take a look at the validator sample in the
documents and samples package.

--
Robin Dunn
Software Craftsman