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
  • 23
  • 6

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
  • 5,793
  • 5
  • 23
  • 56
0

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

tkinter.Tk()

But like:

Tk()
ouflak
  • 2,408
  • 10
  • 40
  • 47
igorbggg
  • 11
  • 2