How to Install Tkinter

Salman Mehmood Feb 02, 2024
  1. Install Tkinter on Windows
  2. Install Tkinter on Linux
  3. Install Tkinter on Mac Operating System
  4. Install Tkinter in Pycharm
How to Install Tkinter

This tutorial will demonstrate how to install Tkinter on multiple platforms. Every platform has individual commands to install Tkinter in Python.

Install Tkinter on Windows

Tkinter offers multiple GUI libraries to develop GUI applications. The Tkinter is one of the popular libraries to build GUI system interfaces.

To install Tkinter, we have to install Python; if it is already installed, we can move on to install Tkinter. When we start the installation of Python, we can check td or tk and IDLE Tkinter during installation.

This way, this Tkinter will come along with Python packages, and we do not need to install it separately. However, if we lose installing Tkinter during the installation of Python, we can do it later using the pip command.

We can confirm the Python version using this command.

python --version

Pip’s version is checked using this command.

pip -V

Now we are ready to install Tkinter.

pip install tk

Now we can use the tkinter library. To confirm the tkinter library is installed, write the code in the shell.

import tkinter
tkinter._test()

If you are an Anaconda user, you can use the following command.

conda install -c anaconda tk

Install Tkinter on Linux

There are different variants of the Linux operating system. This section will learn how to install Tkinter in multiple variants.

Use this command if you’re using a Debian-based Linux operating system.

# python2 user
sudo apt-get install python-tk
# python3 user
sudo apt-get install python3-tk

Use this command if you’re using one of these: RHEL, CentOS, Oracle Linux.

sudo yum install -y tkinter tk-devel

The Fedora-based Linux operating system uses this command.

sudo pacman -S tk

Use this command to confirm the tkinter library is installed successfully.

python -m Tkinter

Install Tkinter on Mac Operating System

There are two ways to install the tkinter library in MacOS. The Mac user will follow these steps.

Run the below command to check that python3 is installed.

python3 --version

Run the below command to check that pip3 is installed.

pip3 --version

If your pip is outdated, please upgrade your pip using the below command.

pip3 install --upgrade pip

We will use pip3 as the first method. Write the following command to install Tkinter.

pip3 install tk

The second method needs a setup.py file to install the Tkinter.

We have to download the latest version of Tkinter in python3 using this command.

curl https://files.pythonhosted.org/packages/a0/81/
742b342fd642e672fbedecde725ba44db44e800dc4c936216c3c6729885a/tk-0.1.0.tar.gz > tk.tar.gz

Write the following command to extract the downloaded package.

tar -xzvf tk.tar.gz

Go to the extracted folder and run this command.

python3 setup.py install

To ensure the tkinter library is installed, run this code in the Python terminal.

import tk

Install Tkinter in Pycharm

The installation process is very simple in Pycharm IDLE. Pycharm IDLE is more convenient for users.

There is an interface to install the tkinter library without running a command.

Go to File>Settings>Project>Python Interpreter and click the + button, search tk, and click the Install Package button. You can select the specific version.

Install Tkinter in Pycharm

Click here to read more about Tkinter.

Salman Mehmood avatar Salman Mehmood avatar

Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.

LinkedIn