From the course: Python GUI Development with Tkinter

Tk and Tkinter background

From the course: Python GUI Development with Tkinter

Start my 1-month free trial

Tk and Tkinter background

- 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 '90s 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 the GUI for your application using Tk, it'll be able to run on most common operating systems. Tkinter is the standard Python interface to Tk framework. When your Python program makes a call to Tkinter, it'll 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 on Windows, it'll take on the native Windows appearance, whereas if I run it in Mac OS, it'll change its 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 theme Tk Widgets for examples in this course whenever they're available.

Contents