Please help - EVT_CHAR

I'm still having problems getting my application to acknowledge keyboard events. I've tried this on two machines, both linux boxes (apparently using wxGTK). Here's my latest attempt...

---start code---
#!/usr/bin/env python

from wxPython.wx import *
class Form1(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        self.My_Text = wxTextCtrl(self, wxNewId(), '', wxPoint(20, 20))

        EVT_CHAR(self, self.kybdEvent)

    def kybdEvent(self, event):
        self.My_Text.WriteText(event.KeyCode())

app = wxPySimpleApp()
frame = wxFrame(None, -1, 'Some Frame')
Form1(frame,-1)
frame.Show(1)
app.MainLoop()
---end code---

What am I doing wrong? Any help would be GREATLY appreciated... TIA

···

__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp

import wx

class Form1(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.My_Text = wx.TextCtrl(self, -1, '', (20, 20))

        self.Bind(wx.EVT_CHAR, self.kybdEvent)

    def kybdEvent(self, event):
        c = chr(event.KeyCode())
        self.My_Text.WriteText(c)

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, 'Some Frame')
Form1(frame, -1)
frame.Show(1)
app.MainLoop()

Regards,

Cliff

···

On Mon, 2004-09-06 at 20:50, jahurt644@netscape.net wrote:

I'm still having problems getting my application to acknowledge keyboard events. I've tried this on two machines, both linux boxes (apparently using wxGTK). Here's my latest attempt...

---start code---
#!/usr/bin/env python

from wxPython.wx import *
class Form1(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        self.My_Text = wxTextCtrl(self, wxNewId(), '', wxPoint(20, 20))

        EVT_CHAR(self, self.kybdEvent)

    def kybdEvent(self, event):
        self.My_Text.WriteText(event.KeyCode())

app = wxPySimpleApp()
frame = wxFrame(None, -1, 'Some Frame')
Form1(frame,-1)
frame.Show(1)
app.MainLoop()

--
Cliff Wells <clifford.wells@comcast.net>

jahurt644@netscape.net wrote:

I'm still having problems getting my application to acknowledge keyboard events.

> I've tried this on two machines, both linux boxes (apparently using wxGTK). Here's my latest attempt...

[code snipped]

What am I doing wrong? Any help would be GREATLY appreciated... TIA

change the EVT_CHAR linr to the following:
EVT_CHAR(self, self.My_Text.GetId(), self.kybdEvent)

you need to tell EVT_CHAR the ID of the control for which
to capture events.

Regards
    Adi

···

--
Adi J. Sieker http://www.sieker.info/
Freelance developer sieker.io – freelance software development

jahurt644@netscape.net wrote:

I'm still having problems getting my application to acknowledge keyboard events. I've tried this on two machines, both linux boxes (apparently using wxGTK). Here's my latest attempt...

---start code---
#!/usr/bin/env python

from wxPython.wx import *
class Form1(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        self.My_Text = wxTextCtrl(self, wxNewId(), '', wxPoint(20, 20))

        EVT_CHAR(self, self.kybdEvent)

    def kybdEvent(self, event):
        self.My_Text.WriteText(event.KeyCode())

app = wxPySimpleApp()
frame = wxFrame(None, -1, 'Some Frame')
Form1(frame,-1)
frame.Show(1)
app.MainLoop()
---end code---

What am I doing wrong? Any help would be GREATLY appreciated... TIA

Only the widget with the keyboard focus will generate CHAR or KEY events, and since they are not command events they are delivered only to the window they happen to, not their parents. Try binding the EVT_CHAR event to the text ctrl by using it for the first parameter of EVT_CHAR().

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!