Python 如何在文本编辑器中添加热键?

Python 如何在文本编辑器中添加热键?,python,wxpython,Python,Wxpython,有一个使用WxPython开发的简单文本编辑器。 我需要添加热键。ctrl+1、ctrl+2、ctrl+3和ctrl+4。因此,当您按下这些热键以执行某些功能时。 我怎么做? 守则: import os import wx class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) self.textBox

有一个使用WxPython开发的简单文本编辑器。 我需要添加热键。ctrl+1、ctrl+2、ctrl+3和ctrl+4。因此,当您按下这些热键以执行某些功能时。 我怎么做? 守则:

import os
import wx
class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title)
        self.textBox = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        fileMenu = wx.Menu()
        menuOpen = fileMenu.Append(wx.ID_OPEN,"O&pen","")
        menuExit = fileMenu.Append(wx.ID_EXIT,"E&xit","")
        menuBar = wx.MenuBar()
        menuBar.Append(fileMenu,"&File")
        self.SetMenuBar(menuBar)
        self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        self.Show(True)
    def OnOpen(self,e):
        self.dirName = ''
        dlg = wx.FileDialog(self, "Choose a file", self.dirName, "", "text file|*.txt", wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.fileName = dlg.GetFilename()
            self.dirName = dlg.GetDirectory()
            f = open(os.path.join(self.dirName, self.fileName), 'r')
            self.textBox.SetValue(f.read())
            f.close()
        dlg.Destroy()
    def OnExit(self,e):
        self.Close(True)

app = wx.App(False)
frame = MyFrame(None, 'RecordBooks')
app.MainLoop()

欢迎来到SO。到目前为止你都试了些什么?结果如何?您是否检查了?如果菜单中有功能,则可以在菜单中指定快捷方式(因此称为“加速器”)-即
“O&pen\tCtrl+1”
-它将在没有任何其他代码的情况下工作。这不是菜单上的菜。我需要一些钥匙来触发一个密码。这是程序的附加功能,请参见,但您必须使用
print()
而不是
print
wx.Window.NewControlId()
而不是
wx.NewId()