What is Tkinter used for and how to install it?

This Python framework provides an interface to the Tk toolkit and works as a thin object-oriented layer on top of Tk. The Tk toolkit is a cross-platform collection of ‘graphical control elements’, aka widgets, for building application interfaces.
If you want to take advantage of the latest version of Tkinter, you’ll need to install a version of Python that supports Tcl/Tk 8.5 or greater. This will provide you with the Ttk (Tile extension integrated into Tk), which is required in order to run the current Tk widget set.
Warning: If you’re working on a system that comes with Python pre-installed, you may need to upgrade it to at least Python 3.7, which includes everything you need to run Tk out of the box.
To verify the Tcl version on your computer, enter:
$ tclsh % info patchlevel 8.6.8
To open a Tcl/Tk shell and verify that it is working, enter a command similar to the following:
On a Linux system:
$ /opt/<tcl_version>/bin/wish8.6
On a Windows system:
C:\Tcl\bin\wish86
A popup window titled wish8.6 will appear.
To verify that Tkinter is properly installed, enter:
$ python -m tkinter
A popup window that states the Tcl/tk version should appear.
What is Tkinter Used For
This framework provides Python users with a simple way to create GUI elements using the widgets found in the Tk toolkit. Tk widgets can be used to construct buttons, menus, data fields, etc. in a Python application. Once created, these graphical elements can be associated with or interact with features, functionality, methods, data or even other widgets.
For example, a button widget can accept mouse clicks, and can also be programmed to perform some kind of action, such as exiting the application.
How to Use Tkinter
In the following example, Tkinter creates a Tk application frame and a button widget that exits the application when clicked.
from tkinter import * tk = Tk() frame = Frame(tk, borderwidth=2) frame.pack(fill=BOTH, expand=1) label = Label(frame, text="Button Example") label.pack(fill=X, expand=1) button = Button(frame, text="Exit", command=tk.destroy) button.pack(side=BOTTOM) tk.mainloop()
How to Download Tkinter for Python 3
As previously stated, the best way to get the latest version of Tkinter is to install Python 3.7 or later. But Tkinter can also be downloaded and installed as part of any standard Python 3 installation.
How to Install Tkinter
If you are using a Python 3 version prior to Python 3.7, or a non-standard version of Python 3 that does not include Tkinter, do the following:
On a Linux System:
$ sudo apt-get install python3-tk
On a Windows or Mac System:
The simplest and easiest method to install Tkinter, is to either:
- Install the latest version of ActiveTcl, or
- Install the latest version of ActivePython
Learn more about installing and verifying Tkinter on Windows here.
Frequently Asked Questions
Where can I find a Tkinter download?
Download ActivePython, which includes the latest version of Tkinter. Or download ActiveTcl, which includes the latest version of Tkinter.
How do I install Tkinter on Windows?
Download ActivePython, which includes the latest version of Tkinter. Or download ActiveTcl, which includes the latest version of Tkinter.
How do I download Tkinter for Python?
Download ActivePython, which includes the latest version of Tkinter.
Which Tkinter version should I download?
Download ActivePython, which includes the latest version of Tkinter.