'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'
Solution 1:[1]
Did you named your python file tkinter.py or Tkinter.py ? Try to rename it. It may be the cause.
Solution 2:[2]
Python 3.x
import tkinter
window = tkinter.Tk()
window.mainloop()
Solution 3:[3]
import tkinter
raiz= tkinter.Tk()
raiz.mainloop()
remember that the file name cannot be tkinter.py
Solution 4:[4]
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
Solution 5:[5]
try Tk instead of tk
it worked for me, if you think you are importing wrong,try:
import tkinter
tkinter._test()
Solution 6:[6]
it's capital 'T' and small 'k' =>> 'Tk' not capital K make sure, small mistake
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Izalion |
| Solution 2 | Paras Dharasanda |
| Solution 3 | Muhammad Dyas Yaskur |
| Solution 4 | Shrimad Bhagwat |
| Solution 5 | TheTechRobo Stands for Ukraine |
| Solution 6 | Sampath |
