DEV Community

Cover image for Basic Tkinter
Saeed Adam
Saeed Adam

Posted on

Basic Tkinter

Many programming languages comes with a GUI library as part of the SDK for developers to enjoy working within the room. It is possible to go for third party library that has the required components which may not be available in the actual SDK.

Tkinter comes in python as a framework built into the python standard libraries (you don't need to look for it outside). Python has many GUI frameworks such as WxPython, PysimpleGUI, Remi, PyQt5 Wax, Pyside, ttkbootstrap, etc, as seconds to the Tkinter.

The Tkinter framework has number of countless visual elements rendered by an active machine, so that the code looks as if the code was developed for the machine. Tkinter is cross-flatform, this means the same code works on different devices, Windows, Linux and MacOs.
Python has the following elements:

  • Lable
  • Button
  • Entry
  • Text
  • Frame
  • Toplevel
  • Canvas
  • Menubutton
  • Message
  • Radiobutton
  • PanedWindow
  • Spinbox
  • MessageBox
  • Scale
  • Scrollbar
  • Checkbutton
  • Menu
  • LabelFrame

Tkinter In Action

Before using tkinter library one must import it into .py file.

from tkinter import *
Enter fullscreen mode Exit fullscreen mode

this ensure all the classes and methods are loaded.
The asterisk (*) tells the engine to import everything inside the class instead of accessing them through dot notation.

Now it is time to instantiate the tkinter class.

window = Tk()
Enter fullscreen mode Exit fullscreen mode

Now we can access all the methods under Tk class using the reference variable window.

To make the app run we must call mainloop() method at the very end of every tkinter program.

window.mainloop()
Enter fullscreen mode Exit fullscreen mode

This will output the following result.

Tkinter window

Thank you for reading.
For further reading click on any component at the very top of the page.
Written by Saeed Adam

Top comments (0)