4

我是 Python 的菜鸟 我读了 wxPython Linux 教程

发现字符串前有'&',例如:

Then we add some items into the menu. This can be done in two ways.


file.Append(101, '&Open', 'Open a new document')
file.Append(102, '&Save', 'Save the document')

Menus are then added into the menubar.


menubar.Append(file, '&File')
menubar.Append(edit, '&Edit')

的含义是&什么?

感谢帮助!

4

1 回答 1

7

It indicates a accelerator letter in the menu.

You can jump to that menu option when the menu is open and you hit that letter on your keyboard, or as a shortcut key together with a modifier key (ALT-F to open the File menu entry, etc.) directly.

From the documentation:

The label string for the normal menu items (not separators) may include the accelerator which can be used to activate the menu item from keyboard. An accelerator key can be specified using the ampersand & character. In order to embed an ampersand character in the menu item text, the ampersand must be doubled.

The use of an ampersand to mark the accelerator key is not limited to wxPython; it is a convention introduced by Microsoft Windows and you'll find it used in many different GUI frameworks. According to Wikipedia:

This convention originated in the first WIN32 api, and is used in Windows Forms, and is also copied into many other tookits on multiple operating systems.

于 2013-08-09T08:52:25.537 回答