Creating menus using wxpython

91 views Asked by At

I created a menu using:

fileMenu = wx.Menu()
fileMenu.Append(ID_NEW, "&New\tCtrl+N", "Creates a new file")

I can access New by clicking it on the menu or by clicking Ctrl+N.

My question is: What is the & stand for?

if I delete it everything is still working. However all guides still use it and none of them explain what is the purpose of it. I've read also here: http://wxpython.org/Phoenix/docs/html/MenuItem.html#MenuItem.SetItemLabel

"An accelerator key can be specified using the ampersand & character ... Optionally you can specify also an accelerator string appending a tab character \t followed by a valid key combination"

So according to this there is no need to use & if I use \t. can someone confirm if my conclusion is correct? I just can't figure why I always see both... there has to be a reason why everyone are using it this way.

2

There are 2 answers

0
mike3996 On BEST ANSWER

The & characters in menu titles indicate an accelerator that you can press while the menu is open to quickly access the item. This only works when the menu is open and focused. You'll see the underscored character in the item title as a mnemonic. Same applies to the top level menu entry as well, such as 'File' or 'Edit': by standard WIMP convention you can open said menu using Alt-F (if F is the accelerator for File) and then just as quickly press 'C' if there is an accelerator for C in that menu. Quick and very little known these days.

The \t means a tab in traditional context and in menu items it will make a global shortcut in your frame that you can press without the menu being active.

0
Hugues Fontenelle On

The shortcut letter following & will be accessible only from the menu.

The \tCtrl+N is available from the entire app, and the short-cut is displayed next to the menu item.