0

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'

panti
  • 21
  • 6
  • 2
    Does this answer your question? [ImportError: No module named 'Tkinter'](https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter) – adist98 Dec 06 '21 at 11:55

2 Answers2

1

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
-1

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

tkinter.Tk()

But like:

Tk()
ouflak
  • 2,458
  • 10
  • 44
  • 49
igorbggg
  • 9
  • 2