我有我的窗户 Wtere这个AttributeError:'NoneType'对象没有属性'tk'???
from Tkinter import *
root = Tk()
root.minsize(428, 285)
root.maxsize(428, 285)
root.resizable(width=NO, height=NO)
root.title("TEST")
root.wm_iconbitmap('C:\Python27\iconfile.ico')
# create the canvas, size in pixels
canvas = Canvas(width = 428, height = 255, bg = 'gray95')
# pack the canvas into a frame/form
canvas.pack(expand = YES, fill = BOTH)
gif1 = PhotoImage(file = 'C:\Python27\image.gif')
# put gif image on canvas
# pic's upper left corner (NW) on the canvas is at x=50 y=10
canvas.create_image(0, 0, image = gif1, anchor = NW)
def die(event):
root.destroy()
b = Button(root, text="text")
b.bind("<Button-1>", die)
b["command"] = die
b.pack()
root.mainloop()
mainloop()
答案 0 :(得分:0)
如果您收到类似“NoneType”对象没有属性“tk”的错误,则表示您的代码中某处有foo.tk()
的内容,并且未定义foo
。查找该行代码并找出未定义foo
的原因。也许你拼错了它,也许你是以错误的顺序称呼它等等。
答案 1 :(得分:0)
尝试写作:
root = Tkinter.Tk()
有时,您需要调用Tkinter来了解程序,以了解Tk()的来源。