I'm a noob with Python I read The wxPython Linux Tutorial
and found that there are '&' before strings, for example:
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')
and
Menus are then added into the menubar.
menubar.Append(file, '&File')
menubar.Append(edit, '&Edit')
What's the meaning of the &
?
Thanks for help!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With