Page 280 -
P. 280
building a graphical user interface
Test Drive
With the code you need extracted from the nongraphical application and
added to your GUI program, press F5 in IDLE to see (and hear) if things are
working any better now:
It not only looks
good, but now it
sounds good, too!
Ting! Splat!
Every time you click on a button, the appropriate sound
effect is heard. Great work!
Q: So “event handlers” in tkinter are just functions? Q: And is it the case that, if I want to add other things to my
GUI program, it’s done in a similar way?
A: Yes, as we said earlier in this chapter: it’s all just code. And
by putting the code you want to run in a function, it’s easy to A: Yes, all you have to do is write the code.
button. Your user clicks the button to run the code in your function. Q: And I connect my code up to my other things using
reference it using the command parameter associated with each
Q: This actually isn’t too hard. I always thought building a something like the command parameter that works with
buttons?
GUI was only for advanced programmers?
A: Yes, that’s all there is to it. The mechanism for the other
A: Well... that certainly used to be the case, but things have interface elements (or widgets, for short) might be a little different,
changed (for the better). Technologies like tkinter allow every but the concept is the same. Once you can work with one, the rest
programmer to build great-looking GUIs without too much fuss. It’s are a lot easier to get your head around.
a case of tkinter concentrating on the GUI, while you concentrate
on your code.
you are here 4 245