_tkinter.TclError:图像“ pyimage2”不存在

时间:2018-12-22 15:52:05

标签: python image tkinter toplevel

尝试运行以下程序时出现以下错误:

_tkinter.TclError: image "pyimage2" doesn't exist

当我使用TopLevel()而不是tkinter.Tk()时,出现了2个窗口,第二个窗口是主窗口。单击“登录按钮”后,再次出现相同的(2nd)窗口

root = tkinter.Tk()

root.title("Facebook Analayzer")

main_font = ("URW Gothic L", 15, "bold")

main_font1 = ("URW Gothic L", 10, "bold")

font3 = ("Nimbus Mono L", 8, "bold")

root.maxsize(height=500, width=500)

root.minsize(height=500, width=500)

canvas = Canvas(root, width=256, height=256)

canvas.pack()

img = PhotoImage(file="fb.png")

canvas.create_image(20, 20, anchor=NW, image=img)

w = Label(root, text="Username", width=40)

w.config(font=main_font, fg="black")

w.pack()

e1 = Entry(root, width="30", bg="yellow")

e1.pack()
  

从评论复制:登录按钮位于代码的最后一行:

b1 = Button(root, 
            text="Login", bg="blue", fg="white", height="2", width="15",
            command=start_prog
           )
b1.config(font=main_font1) 
b1.pack()

1 个答案:

答案 0 :(得分:0)

尝试使用 img = tkinter.PhotoImage(file =“ fb.png”)

不需要tkinter.toplevel()。