+ 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

21st Dec 2018, 2:25 PM
Alireza Mahdian
Alireza Mahdian - avatar
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 *
21st Dec 2018, 3:02 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Thanks for your help "kinshuk Vasisht"
21st Dec 2018, 3:22 PM
Alireza Mahdian
Alireza Mahdian - avatar
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?
4th Sep 2019, 11:54 AM
Mehr Abrar Luck
Mehr Abrar Luck - avatar
0
.def hello(): print()('Hello There') In the function above just place the string inside the print() function not outside of it
10th Oct 2019, 3:26 PM
Subhash Manadhata
Subhash Manadhata - avatar
0
Hi. I also have this problem but it is generated by a text widget. How do I fix it?
30th Oct 2020, 7:07 PM
Lena He
Lena He - avatar
0
Thnx a lot it really helped
25th Jul 2024, 2:36 AM
Mohsin Chunawala
Mohsin Chunawala - avatar