Tkinter comes with Python on Windows and Mac, but you may need to install it separately on Linux
Tkinter is Python's built-in library for creating windows and buttons and text boxes — the visual parts of programs that users click on. On Windows and Mac, it arrives automatically when you install Python. On Linux, you need to run one command in the terminal to add it. This guide walks you through checking whether you have it, and installing it if you don't.
The steps differ slightly by operating system, so find your system below and follow those instructions. The whole process takes a few minutes, and you will know immediately whether it worked by running a single test command.
Key Takeaways
- Windows and Mac users get Tkinter automatically with Python, but you should verify it is there before writing code.
- Linux users must install Tkinter separately using their system's package manager — the command depends on whether you use Ubuntu, Fedora, or another distribution.
- You can test whether Tkinter is installed by opening a terminal and running a single import command that displays a test window.
- If the test fails, the installation command for your system will fix it in under a minute, and you can verify the fix immediately.
Check if Tkinter is already installed
Before you install anything, verify that Tkinter is not already on your computer. Open a terminal or command prompt and type the command below, then press Enter:
python -m tkinter
If a small window appears with a button labeled "Click me!", Tkinter is installed and working. Close that window and you are done — you do not need to install anything. If you see an error message instead, follow the installation steps for your operating system below.
On some systems, you may need to type python3 instead of python. If the first command does not work, try running python3 -m tkinter and see whether the test window appears.
Install Tkinter on Windows
Most Windows users have Tkinter already, but if the test above failed, you need to reinstall Python and make sure Tkinter is included. Go to python.org, download the latest Python installer for Windows, and run it.
When the installer opens, look for a checkbox labeled "tcl/tk and IDLE". Make sure it is checked. If you are using an older version of the installer, this option may appear under "Optional Features" instead. Then click "Install Now" or "Customize Installation" and proceed. The installer will add Tkinter to your Python setup.
After installation finishes, open a command prompt and run the test command again to confirm Tkinter is working. If the test window appears, the installation is complete.
Install Tkinter on Mac
Like Windows, Mac includes Tkinter with Python from python.org. If the test command failed, download the latest Python installer from python.org, run it, and follow the prompts. The installer handles Tkinter automatically — you do not need to select any special options.
If you installed Python using Homebrew instead of the official installer, run this command in the terminal:
brew install python-tk
Homebrew will download and install the Tkinter package for your version of Python. When it finishes, test again with the command from the earlier section to confirm the installation worked.
Install Tkinter on Ubuntu or Debian Linux
Linux distributions do not include Tkinter by default. Open a terminal and run this command:
sudo apt-get install python3-tk
The system will ask for your password. Type it and press Enter. The installation takes a minute or two as the package manager downloads and installs Tkinter. When it finishes, test Tkinter with the command from the earlier section to verify it is working.
If you see a message saying the package was not found, make sure you are using Python 3. Some older systems still have Python 2 as the default, and the package name may be different.
Install Tkinter on Fedora or Red Hat Linux
If you use Fedora, CentOS, or another Red Hat-based distribution, open a terminal and run this command instead:
sudo dnf install python3-tkinter
Enter your password when prompted. The package manager will download and install Tkinter. After installation completes, test Tkinter using the command from the earlier section. The test window should appear, confirming that everything is set up correctly.
On very old Fedora systems, you may need to use yum instead of dnf. If the command above does not work, try sudo yum install python3-tkinter instead.
Verify your installation with a simple program
Once the test window appears, you can write a small program to confirm everything works. Open a text editor, paste the code below, and save the file as test_tkinter.py:
import tkinter as tk window = tk.Tk() window.title("Tkinter Works") label = tk.Label(window, text="Tkinter is installed") label.pack() window.mainloop()
Open a terminal, navigate to the folder where you saved the file, and run:
python test_tkinter.py
A window should appear with the text "Tkinter is installed". If it does, your installation is complete and you are ready to build programs. You can now import Tkinter in any Python script and start creating graphical interfaces.
Frequently Asked Questions
Do I need to install Tkinter if I am using an IDE like PyCharm or VS Code?
No. Those programs use the same Python installation on your computer, so if Tkinter is installed for Python, it works in your IDE. You still need to run the test command to verify it is there, because the IDE cannot use Tkinter if it is missing from your Python setup.
What if the test command says "No module named tkinter"?
This means Tkinter is not installed. Follow the installation steps for your operating system. If you are on Windows or Mac and the installer did not work, try downloading Python again from python.org and making sure the Tkinter checkbox is selected during installation.
Can I use Tkinter with Python 2?
Tkinter exists for Python 2, but Python 2 is no longer supported. Use Python 3 instead. If you have both versions installed, make sure you are running python3 instead of python when you test and when you run your programs.
Is Tkinter the only way to build a graphical interface in Python?
No. Other libraries like PyQt, Kivy, and wxPython also create windows and buttons. Tkinter is the simplest to install because it comes with Python, which makes it a good starting point for learning.
Why does my Mac ask me to install command line tools when I run the test?
Some Mac systems require Xcode command line tools to run Python. Click "Install" when prompted, and the system will download and set up the tools automatically. This is a one-time step and takes several minutes.