Home > front end >  No module named 'tkinter' and doesn't import
No module named 'tkinter' and doesn't import

Time:12-07

I installed tkinter and my python version is 3.6.9 but it still doesn't import

import tkinter

from tkinter import *
root = tkinter.Tk(  )
for r in range(3):
   for c in range(4):
      tkinter.Label(root, text='R%s/C%s'%(r,c),
         borderwidth=1 ).grid(row=r,column=c)
root.mainloop(  )

error is import tkinter ModuleNotFoundError: No module named 'tkinter'

CodePudding user response:

Maybe it's happening because of an installation error. So, please make sure that tkinter is installed properly. like, for ubuntu or other distros with apt,

sudo apt-get install python3-tk

additionally, for me, it's always the best way to run a project is via a virtual environment. So, after checking the installation, if it again doesn't run, try this after creating a virtual environment.

CodePudding user response:

If you are importing all from tkinter (from tkinter import *), you should call functions not like:

tkinter.Tk()

But like:

Tk()
  • Related