problems listening for an event

1) Can anyone tell me why the code that's commented fails to call
the event handler:

class MyFrame(wx.Frame):
    def __init__(self, mytitle):
        wx.Frame.__init__(self, parent=None, title=mytitle)
        mypanel = wx.Panel(self)

        mybutton = wx.Button(mypanel, -1, "click me")
        self.Bind(wx.EVT_BUTTON, self.doSomething, mybutton)

        #myTextBox = wx.TextCtrl(mypanel, -1, pos=(0, 100))
        #self.Bind(wx.EVT_KEY_DOWN, self.doSomething, myTextBox)

        myTextBox = wx.TextCtrl(mypanel, -1, pos=(0, 100))
        myTextBox.Bind(wx.EVT_KEY_DOWN, self.doSomething)
        
    def doSomething(self, event):
        print("hello")

class MyApp(wx.App):
    def __init__(self):
        wx.App.__init__(self, redirect=False)

app = MyApp()
win = MyFrame("test")
win.Show()
app.MainLoop()

7stud wrote:

1) Can anyone tell me why the code that's commented fails to call the event handler:

Sure. I don't think a KEY_DOWN event is a command event, so it only goes to the Window it was generated in.

http://wiki.wxpython.org/self.Bind_vs._self.button.Bind

-chris

···

--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Christopher Barker <Chris.Barker <at> noaa.gov> writes:

Sure. I don't think a KEY_DOWN event is a command event, so it only goes
to the Window it was generated in.

Thanks.