Module ‘tkinter’ has no attribute ‘Tk’

Posted on

Question :

Module ‘tkinter’ has no attribute ‘Tk’

Tkinter doesnt contain any tk attribute.

import tkinter

window = tkinter.Tk()

win.mainloop()

While running this code it gives me an error saying

module 'tkinter' has no attribute 'Tk'

Answer #1:

Did you named your python file tkinter.py or Tkinter.py ? Try to rename it. It may be the cause.

Answered By: Izalion

Answer #2:

Python 3.x

import tkinter

window = tkinter.Tk()

window.mainloop()
Answered By: Paras Dharasanda

Answer #3:

import tkinter

raiz= tkinter.Tk()

raiz.mainloop()

remember that the file name cannot be tkinter.py

Answered By: Ricardo Oviedo

Answer #4:

try ‘Tk’ instead of ‘tk’
it worked for me, if you think you are importing wrong,try:
import tkinter
tkinter._test()

Answered By: mitsu_senpai

Answer #5:

Try copying the file to the Python path in C drive (in my case)

And the folder should not contain any other file named Tkinter.py or similar for Code click here

Answered By: Shrimad Bhagwat

Leave a Reply

Your email address will not be published.