DEV Community

M.ROHAN FAROOQUI
M.ROHAN FAROOQUI

Posted on • Originally published at rohanfarooqui.Medium on

Intro — What is Tkinter ?

In this blog, I’m going to explain the what is Tkinter. Its link with Tcl/Tk and uderlying structure of Tkinter?. What are widgets in Tkinter ?

Intro — What is Tkinter ?

Tkinter is a Python GUI framework. It allow you to convert you console script to a GUI application. You can easily build small application with this library and best part is that it is supported by all OS i.e Linux, Windows and MacOS. Tkinter library was written by Steen Lumholt and Guido van Rossum.

Now let’s talked about Tcl/Tk and its link with Tkinter.

What is Tcl ?

TCL stands for “Tool Command Language”. It is a string based scripting language that allow applications to communicate with each other.

What is Tk ?

Tk stands for “Tool Kit”.It was GUI library designed for scripting language such as TCL. It provide different widgets (like button, entry etc) which help us to build a Graphical User Interface.

How Tkinter is linked with Tcl/Tk ?

We know that in python we can use a library using “import”. The issue is that Tcl/Tk cannot be accessed directly in python with this method, so there is module “tkinter” in python which allow us to access the services of Tcl/Tk for building a Graphical User Interface.

What is meant by Structure of Tkinter program ?

Structure of Tkinter program mean that whats steps are include inorder to build a GUI. Following are the steps:

  1. Import Tkinter Modules :

    First we will import tkinter library in python same as we import other lib in python. Like : import tkinter as *.

  2. Create Main Window :

    The very first window is known as “Main Window” or “Root Window”. By “Main / Root window” we means that the window on which the GUI widgets like entry box ,button appear.

  3. Add Widgets to App :

    Widgets
    are the objects which illustrate information or allow user to interact with the program. Like if user wants to send email then there must be a “Send Email” button which user press. There are total 19 widgets provide in tkinter. You can check all on this link : Widgets List.

  4. Main Event Loop :

    Main Event loop
    run the tkinter application i.e create Root Window and then listen for event calls using** “Event loop” . Event calls are like button presses or mouse click. “Event Loop” run until the all windows of tkinter are not destroyed. It is infinite loop as it continuously running and listening for event calls. “Main / Root window”** will not appear until the main Eventloop is not written.

Tkinter Hello World :

let see a Tkinter Hello World program.

  1. Import tkinter library first

  2. This part of code will create "Main / Root window". But "Main / Root window" will not appear as the mainloop is not called.

  3. Now we will add a label widget and write a text “Hello World”. The following part create the label.
    Create Main Root Window

  4. Now we will call the mainloop which will run the whole program and create a label with text “Hello World”.
    Create Main Root Window

Complete Code :

Output:

  

That’s all for now. If you enjoyed this article, share it with your friends and colleagues and Comment below your thoughts !!

Top comments (0)