Join Barron Stone for an in-depth discussion in this video Installing Python 3 and Tcl/Tk for Windows, part of Python GUI Development with Tkinter.
If you're a Windows user, you're on luck because the standard Python windows installer includes both Tcl/Tk and the Tkinter Python module. This makes the installation process very simple. In fact, if you've already installed Python on your Windows machine, then it's very likely you already have everything you need to use Tkinter. In this video, I'll walk you through the entire Python windows installation process, beginning with downloading the installers. After that, I'll show you how to verify that Tcl/Tk and Tkinter have been properly installed in your machine and are functioning correctly.
To get the Python installer, go to the download page at python.org/download. Select the version of Python you want to install. In this case, I'm going to choose the Python 3.4.1, 64 bit installer and click the link to begin the download. After the download is completed, run the dot MSI installer file. This will bring up the Python 3.4 installer. Just click next to continue through the installation prompts and continue until you get to this page. Here you can see that there's an installation option for Tcl/Tk.
If I select it, it shows that Tkinter, Idle, and pydoc will be installed as part of this item. By default, it should be selected as a feature to be included in the installation, and that's what we want. So you shouldn't need to change anything. Just click next to continue with the installation. After the installer is completed, we'll want to verify that Tkinter and Tcl/Tk were installed and configured correctly. To do that, I'm going to open up Idle and we can access Idle on Windows 8 by pressing the Windows key, going to the search feature, typing Idle.
You'll see here it selects Idle, the Python Gue, and I'll run that. Idle is the integrated development environment that's included with Python. You can use Idle to perform the checks I'm about to show you on your machine or you can run the Python interpreter from another shell program of your choice. First, let's try importing the Tkinter package by typing import Tkinter. Notice that Tkinter is spelled with all lowercase letters. Press enter. If we don't get any error messages, then it means that Python has successfully found and imported the Tkinter package.
Next, type import underscore Tkinter. Be sure to include the underscore before Tkinter and press enter. This will import the compiled binary associated with the Tkinter package. Now that we've successfully imported the Tkinter package, let's run the included test routine. Type Tkinter dot underscore test, open and close parentheses. Press enter and you should see a pop-up window like this one.
If you clicked on the "Click me" button, it should add brackets around the text and the Window should also tell you what version of Tcl/Tk you're running on your machine. You can exit out of this window by clicking the quit button. If all of this runs without error, then you're good to go with Tkinter. Now one last thing I want to point out is that Idle is actually written in Python using that Tkinter package. If you look in the taskbar, you notice the little Python logo down here. This is the same logo you'll see when you run your own Tkinter programs.
This means that just by virtue of successfully opening Idle, I already know that Tkinter is working on my machine. However, as I mentioned before you can still perform this test for Tkinter without Idle by running the Python interpreter in another shell application.
- Installing Python 3 and Tcl/Tk for Mac or Windows
- Creating and configuring themed Tk widgets
- Decorating the GUI with text labels and images
- Capturing input from buttons, menus, and entry fields
- Presenting choices with check boxes and radio buttons
- Using geometry managers to lay out the GUI
- Organizing widgets inside of frames and windows
- Handling user actions with event-driven programming
- Creating a simple drawing tool with the Canvas
- Prompting users with pop-up dialog boxes