need fix Tkinter Error
I have my windows Wtere this AttributeError: 'NoneType' object has no attribute 'tk' ???
from Tkinter import *
root = Tk()
root.minsize(428, 285)
root.ma开发者_运维知识库xsize(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()
If you get an error like "NoneType' object has no attribute 'tk'", it means somewhere in your code you have something that looks like foo.tk()
, and foo
is not defined. Look for that line of code and figure out why foo
is not defined. Maybe you misspelled it, maybe you are calling it in the wrong order, etc.
Try writing:
root = Tkinter.Tk()
Sometimes, you need to call upon Tkinter for the program to understand where Tk() is from.
精彩评论