You probably need to install it using something similar to the following:
For Ubuntu or other distros with Apt:
sudo apt-get install python3-tkFor Fedora:
sudo dnf install python3-tkinter
You can also mention a Python version number like this:
-
sudo apt-get install python3.7-tk -
sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64
Finally, import tkinter (for Python 3) or Tkinter (for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
Answer from d-coder on Stack OverflowYou probably need to install it using something similar to the following:
For Ubuntu or other distros with Apt:
sudo apt-get install python3-tkFor Fedora:
sudo dnf install python3-tkinter
You can also mention a Python version number like this:
-
sudo apt-get install python3.7-tk -
sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64
Finally, import tkinter (for Python 3) or Tkinter (for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
If you're using Python 3.9 on Mac, you can simply install tkinter using Homebrew:
brew install [email protected]
This fixed it for me.
As mentioned by others, you can also use the general command to install the latest version:
brew install python-tk
Videos
Hi everyone,
Im working in a project using Python and I ran into an issue regarding tkinter. The first time a execute the testing code:
from tkinter import *
from tkinter import ttk
root = Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0)
root.mainloop()
Gave me the following error --> ModuleNotFoundError: No module named 'tkinter'
Im using Fedora so I proceed installing tkinter using "sudo dnf install python3-tkinter" command. And when I run "python3 -m tkinter" from terminal it shows the pop-up window. But i keep ran in into the same error when I execute the code from VSC.
Anyone had an idea of how to solve this?
thank you all!
i'm running into this error while trying to use tkinter. tried to sudo apt-get install python3-tk but still same problem.
Ubuntu version: VERSION="20.04.4 LTS (Focal Fossa)"
python: 3.12