【问题标题】:_tkinter.TclError: image "pyimage2" doesn't exist_tkinter.TclError:图像“pyimage2”不存在
【发布时间】:2018-12-22 15:52:04
【问题描述】:

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

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

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

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

【问题讨论】:

标签: python image tkinter toplevel


【解决方案1】:

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

并且不需要 tkinter.toplevel()。

【讨论】:

  • 你好 Prithivi Raj !如果您的答案很简短并且没有完全解决问题,最好发表评论!
猜你喜欢
  • 2014-11-23
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多