首页 > 解决方案 > _tkinter.TclError:图像“.64485752”不存在

问题描述

我写了一个重启程序,但它不起作用

retry = Button(text="play again", width=11, bg="black", fg="grey99", command=restart)
retry.pack()

重启功能如下

def restart():
    global window
    window.destroy()  # destroy and create a new one
    window = Tk()
    global screenheight
    global screenwidth
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    window.geometry("{0}x{1}+0+0".format(window.winfo_screenwidth(), window.winfo_screenheight()))
    window.title("Predict future")
    canvas = Canvas(window, width=screenwidth, height=screenwidth, bg="ghost white")
    canvas.place(x=500, y=300)
    taiji = PhotoImage(file="taiji.gif")
    taijitu = Label(image=taiji)
    intro = Button(window, image=taijitu, command=New)
    intro.place(x=-120, y=-60)

所以它只是破坏旧的并创建一个新窗口,但照片图像没有显示(我猜它已经被垃圾收集了)。

标签: pythonpython-3.x

解决方案


推荐阅读