Chapter 1. Meet Tkinter

Welcome to the exciting world of GUI programming with Tkinter. This project aims at getting you acquainted with Tkinter, the built-in graphical user interface (GUI) interface for all standard Python distributions.

Tkinter (pronounced tea-kay-inter) is the Python interface to Tk, the GUI toolkit for Tcl/Tk.

Tcl (pronounced "tickle" and is an acronym for Tool Command Language) is a popular scripting language in the domains of embedded applications, testing, prototyping, and GUI development. Tk on the other hand is an open source, multiplatform widget toolkit that is used by many different languages for building GUI programs.

The Tkinter interface is implemented as a Python module, Tkinter.py, which is just a wrapper around a C-extension that uses Tcl/Tk libraries.

Tkinter is suited for application to a wide variety of areas ranging from small desktop applications, to use in scientific modeling and research endeavors across various disciplines.

We believe that the concepts you will develop here will enable you to apply and develop GUI applications in your area of interest. Let's get started!

Mission Briefing

The purpose of this project is to make you comfortable with Tkinter. It aims at introducing you to various components of GUI programming with Tkinter.

By the end of this project, you will have developed several partly functional dummy applications such as the one shown as follows:

Mission Briefing

The applications developed in this project are "dummy applications" because they are not fully functional. In fact, the purpose of each small dummy application is to introduce you to some specific aspects of programming with Tkinter. This will set up the context for developing some fun and fully functional project ideas from Project 2, Making a Text Editor, onwards.

Why Is It Awesome?

The ability to program a GUI application (as opposed to a simple console application) opens a whole world of possibilities for a programmer. It shifts the focus of the program from the programmer to the end user, enabling the programmer to reach out to a wider audience.

When a person learning Python needs to graduate to GUI programming, Tkinter seems to be the easiest and fastest way to get the work done. Tkinter is a great tool for programming GUI applications in Python.

The features that make Tkinter a great choice for GUI programming include:

  • It is simple to learn (simpler than any other GUI package for Python)
  • Relatively little code can produce powerful GUI applications
  • Layered design ensures that it is easy to grasp
  • It is portable across all operating systems
  • It is easily accessible as it comes pre-installed with standard Python distribution

None of the other GUI toolkits has all of these features at the same time.

Your Hotshot Objectives

The key concepts that we want you to take from this project include:

  • Understanding the concept of root window and main loop
  • Understanding widgets—the building blocks for your programs
  • Acquainting yourself with a list of available widgets
  • Developing layouts using three geometry managers: pack, grid, and place
  • Learning to apply events and callbacks to make your program functional
  • Styling your widgets with styling options and configuring the root widget

Mission Checklist

An elementary knowledge of data structures, syntax, and semantics of Python is assumed. To work along with this project, you must have a working copy of Python 2.7.3 installed on your computer.

The Python download package and instructions for downloading for different platforms are available at http://www.Python.org/getit/releases/2.7.3/.

We will develop our application on the Windows 7 platform. However, since Tkinter is truly cross-platform, you can follow along on Mac or Linux distributions without any modifications to our code.

After the installation, open the IDLE window and type:

>>>from Tkinter import *

If you have installed Python 2.7, this shell command should execute without any errors.

If there are no error messages the Tkinter module is installed in your Python distribution. When working with examples from this book, we do not support any other Python version except for Python 2.7, which comes bundled with Tkinter Tcl/Tk Version 8.5.

To test if you have the correct Tkinter version on your Python installation, type the following commands in your IDLE or interactive shell:

>>> import Tkinter
>>>Tkinter._test()

This should pop up a window where the first line in the window reads This is Tcl/Tk version 8.5. Make sure it is not 8.4 or any earlier version, as Version 8.5 is a vast improvement over its previous versions.

You are ready to code your Tkinter GUI applications if your version test confirms it as Tcl/Tk version 8.5. Let's get started!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.140.68