Search Here

Creating GUI in Python using Tkinter

 GUI stands for Graphical User Interface, and the name Tkinter comes from "Tk interface", it's mean that you can design and develop GUI or Cool Interfaces using this Python great module named Tkinter. Python gives you a lot of options for developing graphical user interfaces (GUIs) and one of them is Tkinter.

Creating GUI in Python using Tkinter

What is Tkinter?

Tkinter is a Python module that provides GUI Toolkit to develop, design, and build Graphical User Interfaces or Desktop Applications. As the name suggests Tkinter (TK Interface), its means by using Tkinter we can create cool interfaces. You can download this cool module for Unix as well as Windows and Macintosh. 

Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way to create GUI applications. Tkinter provides a powerful object-oriented (OOI) interface to the Tk GUI toolkit.

How Tkinter helps to create GUI's

To create Graphical User Interfaces by using Tkinter is not rocket science. Below are the steps or guidelines to build Applications or GUI using Tkinter.

  • Import the Tkinter module
  • Create Main Window for your Graphical User Applications (Desktop Based Apps)
  • Add your desired widgets like Buttons, CheckButton, Frames, etc
  • Create an action against each widget or event, triggered by the user

Event Handling and Binding used by Tkinter

In Tkinter, an event is simply an action. For example, clicking a mouse button, pressing a keyboard button or changes in the GUI is an event. In Tkinter, we can handle these events by binding them to the user-defined or built-in functions.

Below are the main events that can be used by an application.

  • Keyboard Events
  • Mouse Events

Events Description
Focusin Keyboard focus moved to a widget
Focusout keyboard focus moved to another widget
Return Enter key depressed by keyboard
Key A key was depressed
Shift-Up Up arrow while holding shift key
Configure Widget changed size or location

Tkinter Widgets

Widgets are controls in any GUI Toolkit. Tkinter provides various controls, such as buttons, labels, and text boxes used in a GUI application and these controls are commonly called widgets. There are currently different types of widgets in Tkinter. 

Below are the name and descriptions of mostly used widgets in Tkinter.

Widget Description
Frame Used as a container, to organize another widgets like button, checkbox etc
Button To display button in your application
Canvas To draw shapes such as lines, polygons, rectangles etc
CheckButton To display number of options in your application (select multiple), like HTML checkbox
Entry Single line text field, for accepting values from user
Label Provide single line caption for other widgets
RadioButton To display number of options (select only one)
Text To display text in your application
tkMessageBox To display message box in your application
Listbox To display list of options in your application

Hope this introductory article will help out you to choose the Tkinter module to build a desktop application using python programming. In our next article, you will learn how to install Tkinter on the windows platform.

Post a Comment

0 Comments