Python GUI Module (tkinter)

Python offers tkinter module to create graphics programs. The tkinter represents 'toolkit interface' for GUI. This is an interface for Python programmers that enable them to use the classes of TK module of TCL/TK language. Let's see what this TCL/TK is. The TCL (Tool Command Language) is a powerful dynamic programming language, suitable for web and desktop applications, networking, administration, testing and many more. It is open source and hence can be used by any one freely. TCL language uses TK (Tool Kit) language to generate graphics. TK provides standard GUI not only for TCL but also for many other dynamic programming languages like Python. Hence, this TK is used by Python programmers in developing GUI applications through Python's tkinter module.

tkinter module general steps

The following are the general steps involved in basic GUI programs:

  1. First of all, we should create the root window . The root window is the top level window that provides rectangular space on the screen where we can display text, colors, images, components, etc.
  2. In the root window, we have to allocate space for our use. This is done by creating a canvas or frame . So, canvas and frame are child windows in the root window .
  3. Generally, we use canvas for displaying drawings like lines, arcs, circles, shapes, etc. We use frame for the purpose of displaying components like push buttons, check buttons, menus, etc. These components are also called 'widgets'.
  4. When the user clicks on a widget like push button, we have to handle that event. It means we have to respond to the events by performing the desired tasks.