GUI programs tend to have more code than simple terminal-based ones. This extra code might look a little daunting to the novice programmer. However, it's not as confusing as it might at first seem.
Every GUI application has a similar structure. Understand this structure and you'll be able to create any number of GUI apps, from the simple to the highly complex.
A typical GUI program has four main parts:• window and widget definition
• top-level window initialisation
• the main window loop
• event handlers
The first two parts define the look and feel of the GUI app. As the number of widgets grows and the design becomes more complex we'll have to increase the quantity of code in these parts.
The next two parts control the runtime operation of the app. After the loop renders the various windows and widgets onto the display it continually checks for new mouse and keyboard events. These events are subsequently processed by the previously defined event handlers.
To demonstrate each of these sections we'll create a simple Tkinter app. But first, let's talk a little more about GUI events.
A post from my Learn Python on the Raspberry Pi tutorial.