Question about EVT_CHAR/EVT_KEY_DOWN handler
"'raf' via wxPython-users" <[email protected]> Wed, 12 Mar 2025 01:49:56 +1100
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'm converting a python-2.7+wxPython-2.8.12.1 program to python3.12+wxPython-4.2.2. I'm testing on macos-10.14. I have a Frame containing a Choice, and two TextCtrl, one for a user name and one for a password. It's a login window. For each of these controls, I do: ctrl.Bind(EVT_CHAR, self.OnChar) And self.OnChar is supposed to handle Ctrl-Q, Ctrl-W, Escape, Tab and Return, and skipping anything else. However, OnChar only gets called when Tab is pressed (but not if Shift is down at the time), and only when the focus is in the first TextCtrl, not the second. So if the focus is in the first TextCtrl, Tab (via OnChar) moves focus to the second TextCtrl, but another Tab there does not call OnChar and the focus stays where it is. Shift-Tab never calls OnChar, but the focus switches between the two TextCtrl. So something is processing some keys, but it's not my OnChar method. I'd really like Return when in the password TextCtrl to trigger OnChar which would effectively click the login button. How can I get the OnChar method to be called when any key is pressed, not just Tab? And to be called when the focus is in any of the controls that have had OnChar bound to EVT_CHAR, not just the first TextCtrl? I looked at: https://wxpython.org/Phoenix/docs/html/wx.KeyEvent.html And saw: To summarize: you should handle wxEVT_CHAR if you need the translated key and wxEVT_KEY_DOWN if you only need the value of the key itself, independent of the current keyboard state. So I tried binding EVT_KEY_DOWN instead of EVT_CHAR. The behaviour changed, but not to what I was hoping for. Now, Tab doesn't invoke OnChar, but Return does, but only when the focus is in the first TextCtrl, not when focus is in the second TextCtrl. Does anyone have an idea of what I'm doing wrong? Also, the above link says: Another difference between key and int events is that... without specifying what an "int event" is. What is it? Further down, it refers to EVT_CHAR as an int event but that constant is used with class KeyEvent. So I'm a bit confused. Thanks, raf -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/wxpython-users/Z9BNlPKmNTQZshpm%40raf.org.