Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning that '&string' in wxpython/python

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!

like image 620
Ezio Shiki Avatar asked Mar 23 '23 20:03

Ezio Shiki


1 Answers

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.

like image 121
Martijn Pieters Avatar answered Mar 31 '23 17:03

Martijn Pieters