是否可以使用“wx.AcceleratorEntry”白色非字母数字字符?如果是的话,我错过了什么?
我检查了wx.MenuItem.SetItemLabel的文档,其中说“加速器可能是任何字母数字字符”,但是如果我尝试将加速器设置为其他字符,例如(,逗号)(。点)(ì)我有严肃的口音)他们被接受并出现在菜单中,但只有逗号才能按下组合键。
这是一个带有(python 2.7)和(wxPython 4.0.1)的例子:
# -*- coding: utf-8 -*-
import wx
class MyForm(wx.Frame):
"""Example frame with a simple menu for accelerators test."""
def __init__(self):
wx.Frame.__init__(self, None, title="Accelerators test")
self.panel = wx.Panel(self, wx.ID_ANY)
menu_bar = wx.MenuBar()
self.SetMenuBar(menu_bar)
decoded_menu = wx.Menu()
first_menu_item = decoded_menu.Append(wx.NewId(), "First\tCtrl+a", "First menu")
second_menu_item = decoded_menu.Append(wx.NewId(), "Second\tCtrl+.", "Second menu")
menu_bar.Append(decoded_menu, "&Decoded")
explicit_menu = wx.Menu()
third_menu_item = explicit_menu.Append(wx.NewId(), "Third", "Third menu")
third_menu_item.SetAccel(wx.AcceleratorEntry(wx.ACCEL_CTRL, ord(",")))
fourth_menu_item = explicit_menu.Append(wx.NewId(), "Fourth", "Fourth menu")
fourth_menu_item.SetAccel(wx.AcceleratorEntry(wx.ACCEL_CTRL, ord(u"ì")))
menu_bar.Append(explicit_menu, "&Explicit")
self.Bind(wx.EVT_MENU, self.on_first, first_menu_item)
self.Bind(wx.EVT_MENU, self.on_second, second_menu_item)
self.Bind(wx.EVT_MENU, self.on_third, third_menu_item)
self.Bind(wx.EVT_MENU, self.on_fourth, fourth_menu_item)
def on_first(self, event):
"""First button event handler."""
print 'First'
def on_second(self, event):
"""Second button event handler."""
print 'Second'
def on_third(self, event):
"""Third button event handler."""
print 'Third'
def on_fourth(self, event):
"""Third button event handler."""
print 'Fourth'
if __name__ == "__main__":
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
我不明白出了什么问题。