2
votes

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'
6
Did you name your file "tkinter.py"? This is probably a duplicate of stackoverflow.com/q/46477882/7432 - Bryan Oakley

6 Answers

25
votes

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

1
votes

Python 3.x

import tkinter

window = tkinter.Tk()

window.mainloop()
0
votes
import tkinter

raiz= tkinter.Tk()

raiz.mainloop()

remember that the file name cannot be tkinter.py

0
votes

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

0
votes

try Tk instead of tk it worked for me, if you think you are importing wrong,try:

import tkinter
tkinter._test()
-1
votes

it's capital 'T' and small 'k' =>> 'Tk' not capital K make sure, small mistake