test02.py 712 B

123456789101112131415161718192021222324252627
  1. import wx
  2. # 快捷键。
  3. class MyFrame(wx.Frame):
  4. def __init__(self, parent, title):
  5. super().__init__(parent, title=title, size=(300, 200))
  6. panel = wx.Panel(self)
  7. self.text = wx.TextCtrl(panel)
  8. self.text.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
  9. self.Show(True)
  10. def on_key_down(self, event):
  11. keycode = event.GetKeyCode()
  12. control_down = event.ControlDown()
  13. if control_down and keycode == ord('S'):
  14. wx.MessageBox("Ctrl+S Pressed!", "Info")
  15. event.Skip() # 如果没有这一句,那么在textctrl内,按键就没有效果。
  16. app = wx.App()
  17. frame = MyFrame(None, "wxPython Keyboard Event Example")
  18. app.MainLoop()