Running python3
to bring me into python, and then simply running import tkinter
results in the following error:
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
However when going into the python
shell (not python3), import tkinter
works fine as expected. How can I get tkinter to work with Python3?
Please note the following:
python3 --version
)/usr/bin/python3
)/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/
idle
in Terminal, but I can't run idle3
virtualenv
or pyenv
or anything like thatYou need a separate Tcl/Tk installation. Try a newer version of the Python3 binary installer from python.org, which bundles Tcl/Tk.
Don't install tkinter
through idle
. Try idle3
. If nothing, install python3-tk
using your OS installer. (I have apt
. I'm on Debian.). Good luck!
Don't use _ in import _tkinter
Use import tkinter
I am Sure that this will work. If it works then tick my answer.
Fist open Command Prompt and run pip install tkinter
Then open your python project and press Ctrl + S. Then run your project. I hope my answer is useful to you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.