Installing Python
You will need Python 3.4 with Tcl / Tk 8.6 installed on your computer. The latest branch of this version is Python 3.4.3, which can be downloaded from https://www.python.org/downloads/. Here, you can find the official binaries for the most popular platforms, such as Windows and Mac OS. During the installation process, make sure that you check the Tcl/Tk option to include the library.
The code examples included in the book have been tested against Windows 8 and Mac, but can be run on Linux without any modification. Note that some distributions may require you to install the appropriate package for Python 3. For instance, on Ubuntu, you need to install the python3-tk
package.
Once you have Python installed, you can verify the version by opening Command Prompt or a terminal and executing these lines:
$ python --version Python 3.4.3
After this check, you should be able to start a simple GUI program:
$ python >>> from tkinter import Tk >>> root = Tk() >>> root.title('Hello, world!') >>> root.mainloop()
These statements create a window, change its title, and run indefinitely until the window is closed. Do not close the new window that is displayed when the second statement is executed. Otherwise, it will raise an error because the application has been destroyed.
We will use this library in our first game, and the complete documentation of the module can be found at https://docs.python.org/3/library/tkinter.html.
Tip
Tkinter and Python 2
The Tkinter module was renamed to tkinter in Python 3. If you have Python 2 installed, simply change the import
statement with Tkinter
in uppercase, and the program should run as expected.