Page 376 -
P. 376
graphical interface elements
Q: The Scale() code on the previous Q: How do I know which graphical Q: So does tkinter work well on all
page has a variable called from_, that is, interface element to use and when? platforms?
the word “from” together with a trailing
underscore. Was that a typo? A: This is really a matter of experience. A: The latest version of tkinter (which
However, a lot of platforms go to great comes with Python 3) is pretty good. If
A: No, it wasn’t a tyop, eh, typo. The lengths to specify exactly when each of you run your tkinter program on a Mac, it
reason for the underscore has to do the elements should be used and for what looks like a Mac OS X program, whereas
with the fact that Python uses “from” as purpose. Of them all, the Macintosh is the on Windows it looks like a Windows
a reserved word. These are words that leader of the pack. Apple’s engineers have application, and on Linux it takes on the
Python uses for its own special purposes, worked hard to strictly enforce consistent look and feel of the graphical environment
which means you cannot name one of your usage of the Mac GUI among programmers. you happen to be using (there are a few
the word “from” makes a lot of sense when Q: choices on Linux).
variables after a reserved word. As using
So, it’s a case of anything goes
taking about a scale, the authors of tkinter with the other operating systems? Q: Other than tkinter, what other
decided to tack on the underscore so that graphical toolkits does Python support,
the meaning of the variable would be clear, and should I learn any of them?
while allowing for the variable name not to A: No. That’s not what we are saying.
clash with a reserved word. The Apple folks are very strict with their
rules and regulations, and the others are A: Python supports lots of other toolkits
Q: Are there other reserved words? less so. But there are still standards that on lots of operating systems. For now,
tkinter is all you really need, and you
you should try as much as possible to
adhere to. One of the reasons for using shouldn’t worry about the other choices
A: Yes, a few. And every programming a GUI is that your users will expect your until you are in a situation where learning
language has its own list. In Python, words program to work in a standard way. This how to use them becomes a necessity.
like “while”, “for”, “if”, “def”, “class”, and makes your program immediately familiar
“pass” are all reserved words. to new users and lets them become
Q: What happens if I use one productive with your program more quickly.
anyway? Q: So there are no badly designed
GUI apps?
A: Python will most likely complain with
a syntax error. A: No. There are plenty of howlers out
Q: Where can I find a list? there... and they tend to be harder to use
than necessary, due to the fact that the
programmers responsible for creating them
did not conform to established interface
A: Any good Python reference book standards and practices. When it comes
will contain a list, and it’s also included as to GUI programs, conformance is a good
part of the Python documentation that’s thing.
installed with Python on your computer and
available on the web at the main Python
website.
you are here 4 341