Join Barron Stone for an in-depth discussion in this video Tk and Tkinter background, part of Python GUI Development with Tkinter.
- View Offline
Before we dive into learning about Python and TkInter, let's talk a little bit about what Tk is first. Tk is an open source toolkit used to develop graphical user interfaces. It provides a library of interactive widgets , which are GUI elements commonly used in desktop applications. These are things like buttons, menus, windows, and text entry fields. Tk was developed back in the early 90's as an extension for a scripting language called tool command language, which is abbreviated as TCL, and often pronounced tickle.
It was designed to be platform independent, and has since been ported to run on most versions of Windows, Mac OS, Unix or Linux. This means that if you develop your GUI application using Tk, it will be able to run on most common operating systems. TkInter is the standard Python interface to the Tk framework. When your python program makes a call to TkInter, it will be accessing functions in the Tkinter package which is written in Python. Those functions parse the commands from your Python program and format them to look like commands from a Tk script.
Then they're passed on to the _tkinter extension module, which is written and compiled in C, and is able to make calls into the Widgets in the Tk library, which is implemented using a combination of C and Tcl. At the end of the chain the Tk widgets utilize the Xlib library to actually draw graphics on the screen. Tk version 8.0 introduced new GUI elements which are themed to match the appearance of the standard elements in your operating system. For example when I run the Python Tkinter script to create this log in screen in windows it will take on the native windows appearance, whereas if I run it in Mac OS it will change it's appearance to fit the Mac theme.
This allows you to write a cross platform GUI application, which will maintain the look and feel of the operating system on which it's currently running. If you're using Python 3.1 or newer, you can access these themed Tk widgets by importing and creating your widgets with the TTK module. We'll be using themed Tk widgets for examples in this course whenever they are available.
- 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