+ 1
[SOLVED] AttributeError: module 'tkinter' has no attribute 'Tk'
I get an error when Run the code below #My Code #----------------------------- def hello(): print()('Hello There') from tkinter import * tk=Tk() btn = Button(tk, text="click me", command=hello) btn.pack() #Error #----------------------------- #AttributeError: module 'tkinter' has no attribute 'Tk' please help me to solve this Error
6 Answers
+ 4
The problem can be that your file is named tkinter.py. Doing that shadows the module you need to import, and you get nothing.
The issue is explained in detailed here:
https://stackoverflow.com/questions/31303719/attributeerror-module-object-has-no-attribute-tk
https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at
Try renaming the source file to something else if you used tkinter.py
If that does not help, use:
import tkinter as tk
instead of:
from tkinter import *
+ 2
Thanks for your help "kinshuk Vasisht"
0
sir this is still insufficient answer and isn't working ...i have the same issue as mentioned above tkinter module has no attribute tk?
0
.def hello():
print()('Hello There')
In the function above just place the string inside the print() function not outside of it
0
Hi.
I also have this problem but it is generated by a text widget. How do I fix it?
0
Thnx a lot it really helped