How to Fix Python ImportError: No Module Named _Tkinter, Please Install the Python-Tk Package
-
the
ImportError: No module named _tkinter, please install the python-tk package
in Python -
Fix the
ImportError: No module named _tkinter, please install the python-tk package
in Python
This article will discuss the ImportError: No module named _tkinter, please install the python-tk package
error in Python and how to fix it.
the ImportError: No module named _tkinter, please install the python-tk package
in Python
Tkinter packages must be installed externally through the CLI
and imported to your program. Otherwise, you will encounter the ImportError: No module named _tkinter, please install the python-tk package
.
Let’s see the example.
Code:
import tkinter
Output:
ImportError: No module named _tkinter, please install the python-tk package
# or
ImportError: No module named _tkinter
Fix the ImportError: No module named _tkinter, please install the python-tk package
in Python
To fix the error, install the tkinter
package externally from the command line interface and then import it into the current program.
There might be a different version of the command based on your operating system (OS), so you can try the one that perfectly matches your OS.
If you have Python 3x then you need to run the following command. This command also works with Ubuntu.
sudo apt-get install python3-tk
Command - Fedora:
sudo dnf install python3-tkinter
Command - Arch Linux:
sudo pacman -S tk
Command - Debian-based and Python 3x:
sudo apt-get install python-tk
Moreover, if you are using RHEL, CentOS, or Oracle Linux, then you can use yum
to install tkinter.
yum install tkinter
Based on your OS, you should install the version that suits your system, then import the tkinter into your current program, and it should work fine.
Let’s try a basic GUI application with tkinter.
Code:
from tkinter import *
window = Tk()
# label
lbl = Label(window, text="Welcome to DelfStack.com", fg="blue", font=("Helvetica", 14))
lbl.place(x=60, y=100)
# title
window.title("DelfStack")
# size of the dialog box
window.geometry("400x200+10+10")
window.mainloop()
Output:
The above code will create a small dialog box, which in this case displays a label "Welcome to DelfStack.com"
and a title "DelfStack"
, but you can add more weights to it accordingly.
Zeeshan is a detail oriented software engineer that helps companies and individuals make their lives and easier with software solutions.
LinkedInRelated Article - Python Error
- Can Only Concatenate List (Not Int) to List in Python
- How to Fix Value Error Need More Than One Value to Unpack in Python
- How to Fix ValueError Arrays Must All Be the Same Length in Python
- Invalid Syntax in Python
- How to Fix the TypeError: Object of Type 'Int64' Is Not JSON Serializable
- How to Fix the TypeError: 'float' Object Cannot Be Interpreted as an Integer in Python