Skip to content

HFP CH 7

Jacob Amey edited this page Aug 19, 2013 · 1 revision

Chapter 7 - Going all gooey

(building a graphical user interface)

40 Pages Long

Description:

Oh man, this chapter. What a time suck it was. Not because the material was hard or drawn out. It turns out getting pygame to install on Fedora 19 64 bit is nothing less then a life altering experience. It took me 2 -3 days with a combined time of probably 5 - 6 hours of work. Almost a full work day just to have pygame installed at the 64 bit level using python 3. I wish i wrote down everting I did because Im sure ill have to do this again when fedora 20 comes out.

I do remember that you need to softlink this libportmidi.so.0 to this libporttime.so in the lib64 directory. you also need to change line 123 of the setup.py from raw_input to input. Besides that happy hunting for all of the dependency files!

after the pygame install is done the chapter is really straight forward covering sound input for button clicks and building GUIs with tkinter. This was easier then I thought it would be! pygame though, that is going to have you screaming for days. Get some chips and coffee and bunker down. Your in for a battle.

The Code:

The code (once pygame is up and running) is pretty fun. You build a simple GUI for a TV show host. It makes different sounds based on wrong or wright answers as well as takes a tally of how many where right and wrong. In the end it was really easy and surprising as to how little code is needed to produce a GUI.

Main Concepts Covered:

  1. Using a third-party programming library.
  2. Playing with a sound library.
  3. Event loops - respond to events when they occur.
  4. Event handler - code that executes when a certain event occurs.
  5. GUI - a graphical user interface.
  6. Widget - a GUI interface element.

Python Tools Covered:

  • pygame - a professional-level set of gaming libraries that support sound.
  • pass - a piece of code that does nothing.
  • break - exit from a loop.
  • tkinter - a standard library for creating GUIs.
  • Tk() - a blank GUI app.
  • Button() - a tkinter button widget.
  • Label() - a tkinter label widget.
  • IntVar() - a tkinter integer variable that can update the GUI "as if by magic".

Clone this wiki locally