Introduction to Tkinter | Getting started – Technoinc

Introduction to Tkinter | Getting started – Technoinc

Python is one of the best programming languages nowadays. With the help of this language, we can do lots of tasks as this is comparatively easy to understand and its syntax is too easy. Using python we can create GUI application and draw different shapes and graphs too.

There are plenty of options available in python for making GUI, which are listed below.

  1. Tkinter − Tkinter is the Python interface to the Tk GUI toolkit shipped with Python.
  2. wxPython − This is an open-source Python interface for wxWindows.
  3. JPython − JPython is a Python port for Java which gives Python scripts seamless access to Java class libraries on the local machine.
  4. PyQt – PyQt is a Python binding of the cross-platform GUI toolkit Qt.

In this we only cover Tkinter. Where we learn how Tkinter is used what is the application of it and also try our hands on some basic command and syntax of Tkinter.

Tkinter is basically python GUI, so it is necessary to have Python on your machine. If it is not then you can first refer our Python blog where you can get how to download and install python.

Here I am going to use Notepad ++ as an editor. You can use PyCharm, Microsoft visual studio or Geany for the lightweight text editor.

Open notepad++ or any text editor in which python language is supported. Basic code of Tkinter is given below. Which is necessary for all GUI programming. With the help of this code, we can create and open a GUI window.

                     Code:- from Tkinter import*
                     root = Tk()

Here first we import all the libraries from Tkinter using import*. Then we create one window to do all our tasks. Here that window is root. We write root=Tk() means we create one main window, name root and which is the main application window in our programs.

Now we are done with our application but we have to run this application too.
For that, we use the main loop(). mainloop() is basically a command to run our application which we made. For that, we have to write our window name and then main loop() followed by .(dot). Here our window name is root so we write root.mainloop() to run our application.

To run the code we can use various ways. Which is also depends on our text editor. I am going to run this code using the command prompt.
For that, you have to first go to your directory where you save the above code.
Then type python and file

Here I saved my code on desktop as
By entering this code one window is open which looks like below.

This is a blank window as we just create one empty window.

In the next blog, we are going to learn about different widgets which we can
use in our application.


Leave a Reply

Your email address will not be published. Required fields are marked *