Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import _tkinter # If this fails your Python may not be configured for Tk error in python 3.8

Currently using Ubuntu 20.04 LTS with python3.8.5. Its my first time using ubuntu with absolutely no previous knowledge of terminal.SO,would love to have a detailed answer if possible. Below is terminal output when i try importing tkinter in python3.

>>> import tkinter  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/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'
>>> 

I have reinstalled python3 and tkinter using sudo apt.But still it shows same error. When i run the same command in python IDLE it works without any error. I hope this explains my problem clearly, if any other info. is required pls reply. I also tried running the command >>>from tkinter import *

like image 242
Atharva Dhamale Avatar asked Aug 29 '20 05:08

Atharva Dhamale


People also ask

How do I import Tk?

Import the Tkinter module. Create the GUI application main window. Add one or more of the above-mentioned widgets to the GUI application. Enter the main event loop to take action against each event triggered by the user.

How do I install tkinter?

The simplest method to install Tkinter in a Windows environment is to download and install either ActivePython 3.8 or 3.7 from here. Alternatively, you can create and activate a Conda environment with Python 3.7 or greater that is integrated with the latest version of Tkinter.

Is tkinter included in Python?

Tkinter is the de facto way in Python to create Graphical User interfaces (GUIs) and is included in all standard Python Distributions. In fact, it's the only framework built into the Python standard library.


Video Answer


1 Answers

I faced the same issue on MacOS. I was using a Python virtual environment. This command worked for me:

brew install python-tk
like image 133
A.Ranjan Avatar answered Nov 15 '22 09:11

A.Ranjan