Page 268 -
P. 268
building a graphical user interface
Frank: Since when have you been an expert on GUIs?
Jim: Isn’t every Windows user? Ah... GUIs. All those lovely event
Joe: Well, of course, everyone knows how to use a GUI, but we are handlers, mouse clicks, widgets, frames,
talking about creating a GUI in code. scroll bars, double clicks and—my
personal favorite—the mouseover.
Jim: Ah... oh... um... eh... now, where shall we start?
Frank: It turns out that writing code for a GUI application is...
well... just like writing any other code. If you know how to program,
you know how to create a GUI. It’s just a matter of selecting the
correct GUI library, learning how to use it, then writing the code.
Joe: So we’ll head off to the Python Package Index and grab us some
GUI libraries, eh?
Frank: Not so fast. Python comes with a GUI library as standard,
called tkinter.
Jim: tk-what?
Frank: tkinter. The “tk” bit refers to the fact that Python’s standard
GUI library is built on top of the very popular Tk technology. The
“inter” bit is short for “interface.”
Jim: So we’re going to build a GUI interface in Python running on
Tk using tkinter?
Frank: Yes, we are. That’s not too confusing, is it?
Joe & Jim: Well... not if you say so.
Frank: The big thing with creating GUIs is understanding the event
loop.
Joe: Ah, that’s just looping code that reacts when certain things Frank
happen, isn’t it? It’s just like the while loop in the non-GUI version Joe
of TVN’s program. In that code, that loop is an event loop, isn’t it?
Frank: It sure is. Although the GUI event loop tends to be extra Jim
capable and can do lots more than the simple while loop.
Joe: That sounds complex. Is it?
Frank: No, not really. It just takes a little getting used to.
Jim: But, it’s all just code, isn’t it?
Frank: Yes, Python code using the tkinter library.
Joe: OK. Let’s get to it, since we already know how to program...
you are here 4 233