Background
Recently I've been trying to learn python and its GUI PyQt4. Codecademy helped me much on how classes work as classes are used very often in PyQt4 (and that Python is an object-oriented language.)I use this really helpful tutorial on PyQt4 to help me get started:
First programs in PyQt4
As I was learning how to use a menu bar, I came to this weird situation.
There was a line of code that adds items into the menu bar.
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
I wasn't quite sure why there was a &(ampersand) in front of the File as it is supposed to be a string that is the name of the item. When I execute the code, the "&" didn't show up either.
Out of curiosity, I tested out using addMenu("File") without the ampersand "&". It turn out fine and shows up just like "&File".
Answer
So this page answered my question.
It states that the ampersand "&" is there in front of the title [e.g. addMenu("&File")] so that the system shortcut " Alt + *the first character of the title* " can connect and open the menu item. For example: "Alt + F" will open the "File" menu and "Alt + H" will open the "hello" menu.
Side notes: if we want the actual ampersand sign in our string, we can use "&&" and it will show up.
Side notes: if we want the actual ampersand sign in our string, we can use "&&" and it will show up.
There are so many details!
No comments:
Post a Comment