Introduction to GUI in Python
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.
The following are the general steps involved in basic GUI programs:
- 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.
- 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.
- 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'.
- 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.
Now, let's proceed further with the top level window or root window and learn to create it.