简体   繁体   English

模块“tkinter”没有属性“Tk”

[英]Module 'tkinter' has no attribute 'Tk'

Tkinter doesnt contain any tk attribute. Tkinter 不包含任何 tk 属性。

import tkinter

window = tkinter.Tk()

win.mainloop()

While running this code it gives me an error saying运行这段代码时,它给我一个错误提示

module 'tkinter' has no attribute 'Tk'

Did you named your python file tkinter.py or Tkinter.py ?您是否将您的 python 文件命名为 tkinter.py 或 Tkinter.py ? Try to rename it.尝试重命名它。 It may be the cause.这可能是原因。

Python 3.x蟒蛇 3.x

import tkinter

window = tkinter.Tk()

window.mainloop()

try Tk instead of tk it worked for me, if you think you are importing wrong,try:尝试Tk而不是tk它对我tk ,如果您认为导入错误,请尝试:

import tkinter
tkinter._test()
import tkinter

raiz= tkinter.Tk()

raiz.mainloop()

remember that the file name cannot be tkinter.py记住文件名不能是 tkinter.py

Try copying the file to the Python path in C drive (in my case)尝试将文件复制到 C 盘中的 Python 路径(在我的情况下)

And the folder should not contain any other file named Tkinter.py or similar for Code click here并且该文件夹不应包含任何其他名为 Tkinter.py 或类似代码的文件,请单击此处

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在我的例子中,错误发生在top =tk.Tk()我使用的简单技巧是将 'TK' 中的大写 K 更改为小写 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')

它是大写的 'T' 和小写的 'k' =>> 'Tk' 不是大写的 K 确保,小错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM