Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:19:04+00:00 2026-06-13T17:19:04+00:00

Well I have come up with some code to check what key is pressed,

  • 0

Well I have come up with some code to check what key is pressed, its pretty basic right now, but as I progress I will update here, the point is to get a key pressed whenever the key event takes place

import wx

class Example(wx.Frame):
    def __init__(self, *args,**kw):
        super(Example, self).__init__(*args,**kw)
        self.InitUI()
    def InitUI(self):
        #frame = wx.Frame(self, style=wx.FRAME_DRAWER | wx.STAY_ON_TOP, size = (100, 100))
        #pnl= wx.Panel(frame)
        pnl= wx.Panel(self)    
        pnl.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
        self.st1 = wx.StaticText(self, label='', pos=(30, 10))
        pnl.SetFocus()
        self.SetSize((250,180))
        self.SetTitle('Key Press Event')
        self.Centre()
        self.Show(True)

    def OnKeyDown(self, e):
        key = e.GetKeyCode()
        if  key==wx.WXK_ESCAPE:
            self.st1.SetLabel("ESCAPE")
        elif key ==wx.WXK_CONTROL:
            self.st1.SetLabel("CTRL")
        elif key==wx.WXK_ALT:
            self.st1.SetLabel("ALT")
        elif key==wx.WXK_BACK:
            self.st1.SetLabel("BACKSPACE")
        elif key== wx.WXK_EXECUTE:
            self.st1.SetLabel("ENTER KEY")
def main():
    ex = wx.App()
    Example(None)
    ex.MainLoop()

if __name__=='__main__':
    main()

I am trying to to a borderless window for this but even if I put the panel in a frame with style= FRAME_DRAWER it doesnt work, neither does the STAY_ON_TOP so those two lines are commented please see if u can make it work..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:19:05+00:00Added an answer on June 13, 2026 at 5:19 pm

    Panels tend to eat key events or pass them on to other widgets. See

    http://wxpython-users.1045709.n5.nabble.com/Catching-key-events-from-a-panel-and-follow-up-to-stacked-panels-td2360109.html

    Which links to an old thread: http://article.gmane.org/gmane.comp.python.wxpython/50485

    Quoting Robin Dunn, creator of wxPython:

    • Bind a key event handler to all the widgets

    • *Catch the EVT_CHILD_FOCUS event and reset the focus back to where you
      want it to be whenever the focus changes to a child.*

    • Use a wx.AcceleratorTable instead of key events, so the keystrokes
      will be turned into menu events no matter which widget in the app has
      the focus.

    • Bind your key handler to the app instead of to the frame. All
      unhandled events are sent to the app object before they are abandoned,
      so whichever widget has the focus, if it doesn’t handle the key event
      itself then the app will get a chance at it.

    You might also find my old tutorial on key events enlightening as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
While analyzing some library code supplied by another company we have come across strange
I have been having problems with this for some time now, and have come
I have some code that needs Unicode strings for the most part, but I
I'm using hibernate JPA (without Spring) and it's working well, but I have come
Well i have a web page hosted in a IIS 7.0 now the problem
Well I have been writing in the same style for awhile now and all
well i have most probably an extremly stupid problem but could not figure it
I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well
I have below code. <table> <tr> <td class=bgimg valign=middle width=10% title=some title nowrap> <img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.