Shubham Verma
Shubham Verma

Reputation: 71

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'

Upvotes: 7

Views: 54885

Answers (8)

Kerem Cavus
Kerem Cavus

Reputation: 23

Your python script name is must not be tkinker.py python could prioritize your script as tkinker and that couldn return that error.

Upvotes: 0

Izalion
Izalion

Reputation: 758

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

Upvotes: 57

Happy Nkanta Monday
Happy Nkanta Monday

Reputation: 429

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')

Upvotes: 3

Sampath
Sampath

Reputation: 21

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

Upvotes: 0

monday
monday

Reputation: 9

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

import tkinter
tkinter._test()

Upvotes: 0

Shrimad Bhagwat
Shrimad Bhagwat

Reputation: 23

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

Upvotes: 0

Ricardo Oviedo
Ricardo Oviedo

Reputation: 31

import tkinter

raiz= tkinter.Tk()

raiz.mainloop()

remember that the file name cannot be tkinter.py

Upvotes: 2

Paras Dharasanda
Paras Dharasanda

Reputation: 213

Python 3.x

import tkinter

window = tkinter.Tk()

window.mainloop()

Upvotes: 1

Related Questions