2010-11-21 119 views
-1

我有我的窗口 這個AttributeError:'NoneType'對象沒有屬性'tk'?需要修復Tkinter錯誤

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()  
+1

回溯是...? – 2010-11-21 21:51:00

+0

我不知道同性戀im noob – Alex 2010-11-21 21:57:00

+0

你發佈的代碼不會給你說的錯誤。 – 2010-11-21 22:41:34

回答

0

如果你得到「NoneType」對象有沒有屬性‘TK’」的錯誤,這意味着地方在你的代碼,你有東西,看起來像foo.tk(),並沒有定義foo。查找該行代碼並找出爲什麼foo未定義。也許你拼錯了,也許你正在調用它以錯誤的順序等

0

嘗試寫:
root = Tkinter.Tk()
有時候,你需要的程序來理解TK()是在Tkinter的調用。