Skip to content

HFP CH 9

Jacob Amey edited this page Aug 19, 2013 · 3 revisions

Chapter 9 - Selecting the right tool

(graphical interface elements)

35 Pages Long

Description:

More GUI tasks in this chapter, I believe the next chapter is all GUI related as well. This book should be called head first GUI programming! (Not complaining, just saying). Anyway in this chapter you learn about and use checkboxes. You also work with the Window Manager a bit more working with default settings and modifying them as needed. You also reintroduce Pygame in to the chapter and work with some other GUI tools to give the program a bit more functionality.

The Code:

In this Chapter you build a sound control system for a DJ. Nothing special at first. You build a gui that lets you start and stop a song (Hope you like Techno). After the first build you learn about how to destroy a GUI allowing you to use the main close button and actually have the song stop playing and go away. In the end you remove the start/stop buttons and introduce a check box and slider for the volume. It was pretty cool making the slider and then having it correctly function.

Main Concepts Covered:

  1. The Window Manager manages the windows created by your GUI.
  2. GUI events can be generated by the operating system, the Window Manager, and your user.
  3. If you redefine some default functionality, be sure to code the default behavior into your code (if required.)
  4. A checkbox lets you indicate whether something is set to ON or OFF.
  5. A scale/slider lets you implement a volume control.
  6. Be sure to look at other GUI programs when looking for inspiration and ideas for your own programs.
  7. Reserved words are names that have special meaning in a programming language and which cannot be used as variable names.

Python Tools Covered:

  • app.destroy() - used to terminate a tkinter GUI application.
  • DoubleVar() - like IntVar and StringVar, but used to hold a floating-point number.
  • Checkbutton() - a tkinter widget for creating checkboxes.
  • Scale() - a tkinter widget for creating scales/sliders.

Clone this wiki locally