Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module 'tkinter' has no attribute 'Tk'

Tags:

python

tkinter

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'
like image 542
Shubham Verma Avatar asked Jun 04 '26 05:06

Shubham Verma


2 Answers

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

if the file name is tkinter.py in program

import tkinter

it will imports the our file name which is overriders the content there is not Tk() module, so it throw the error

like image 79
Izalion Avatar answered Jun 05 '26 17:06

Izalion


In my case, the error occurred in top =tk.Tk() The simple trick I used was to change the uppercase K in 'TK' to lowercase k

import tkinter as tk
import tkinter.filedialog as fd
from tkinter import *
import PIL
from PIL import ImageTk
from PIL import Image
top =tk.Tk()
top.geometry('800x600')
top.title('Image Processing')
top.configure(background='#CDCDCD')
like image 39
Happy Nkanta Monday Avatar answered Jun 05 '26 19:06

Happy Nkanta Monday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!