top of page

Python GUI - Tkinter

Updated: Oct 19, 2021



What is Tkinter

Tkinter is an inbuilt python module which is used for building the simple Graphical User Interface (GUI) application. Tinkter relies on the Tk library, the GUI library used by Tcl/Tk and Perl, which is in turn implemented in C. Hence, Tkinter can be applied using multiple layers. This is an open-source package and is available on most Unix platforms, including macOS and windows systems.

What is GUI

GUI is a desktop application which helps you to interact with computers. e.g Google chrome, sudoku game, text editor, calculator etc.

Why Tkinter

  • Tkinter is easy to understand and fast to implement compared to other GUI toolkits.

  • The layered approach used in designing Tkinter gives Tkinter all the advantages of the Tk library

  • It provides the simple syntax

  • It is more flexible and stable

  • Tkinter is now included in the Python distribution. Hence no supplementary modules are required in order to run script using tkinter.

  • It does not require any modification to be ported from one platform to another because tkinter is available for the most unix platform, mac os and windows system.

Getting started with Tkinter

To use Tkinter, First thing We need to do is import the python GUI tkinter module using the following command.

Import tkinter as tk 	

Create an simple empty GUI window

As a first step toward building a GUI, we can create an empty gui window using tkinter,

Example of code


import tkinter as tk
window = tk.Tk() 
window.mainloop()

A tkinter.Tk (tk.Tk) object creates a tkinter-based GUI, Due to this a window pops up on your screen. We make the Tkinter GUI active by calling the mainLoop() function. tkinter provides the event loop.

When execute the above code, a new window will pops up on your screen


Output :


Tkinter Widgets

A widget is an element of a graphical user interface(GUI) that helps users to interact with the computers and it displays information on screen. There are various widgets like button, Label, Menu, Canvas that are used to build the GUI application.

Here are some Basic Widgets which are used in GUI applications.

Button : A button is a widget which is designed to interact with computers. If the button is pressed then some action might be started.

Menubutton : The menu button is used to display the list of menu items to the user. It is used to add the drop down menu

Canvas : It is used to add the structured graphics, draw the graph and plots to the python application.

Menu : Menu widgets are used to add menu items to the user.

Text : Text widget is used to insert the multiline text field.

Label : It is used to display text on the screen.

Checkbutton : Checkbutton widget is used to implement on/off selections.

Listbox : The ListBox widget is used to display a list of options to the users.

Lets see Basic program, Create a simple Hello world GUI application

In the below Example we use tk.Label() class to add some text to the window. Create a Label widget with the text “Hello World!” and assign it to a variable called welcome. After that we use label widgets .pack() method to add the widget to the window.

Example code


import tkinter as tk
window = tk.Tk() 
welcome= tk.Label(text="Hello World!")
welcome.pack()
window.mainloop()

When executing the above code this output will be shown on the screen .


Output :



If you want to know more about tkinter click Here




How Codersarts can Help you in Python GUI tkinter ?


Codersarts provide:


  • Python GUI tkinter Assignment help

  • tkinter Error Resolving Help

  • Mentorship in tkinter from Experts

  • tkinter Development Project


If you are looking for any kind of Help in tkinter Contact us

Opmerkingen


bottom of page