Blast off

Your program's looking pretty dated.

The program works, but it's not going to win a Visual Design Award any time soon. And its use of key presses makes it a little hard to use, too.

So, its looks could be improved and its usability could be better.

It sounds like you need a graphical user interface, or GUI.

Most people pronounce GUI as "gooey."

You need to design the look of your GUI for TVN. Draw what you think your GUI should look like in the space provided below.

Hint: Take some time to think about other GUI programs that you have used. Think about a common interface element that you could use (and draw) here.

interface facelift

You needed to design the look of the GUI for TVN. You were asked to draw what you think your GUI should look like in the space provided below.

host will ihe press this button when the answer is torrett press this button when the answer is torrett

ihis buiio, the answer ls wrong.

You need two buttons f°v each of your program's events.

ihis buiio, the answer ls wrong.

You need two buttons f°v each of your program's events.

Frank: Since when have you been an expert on GUIs? Jim: Isn't every Windows user?

Joe: Well, of course, everyone knows how to use a GUI, but we are talking about creating a GUI in code.

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.

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 happen, isn't it? It's just like the while loop in the non-GUI version 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 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.

Frank: Yes, Python code using the tkinter library.

Joe: OK. Let's get to it, since we already know how to program...

Ah... GUIs. All those lovely event handlers, mouse clicks, widgets, frames, scroll bars, double clicks and—my personal favorite—the mouseover.

tkinter event loop

Was this article helpful?

0 0

Post a comment