本文介绍了'图像“pyimage2"不存在'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是发现错误的地方:

global backbuttonimg
backbuttonimg = PhotoImage(file="backbutton.gif")
C6 = tkinter.Button(W_CheckDates, image=backbuttonimg, command = CheckDatesBack)
C6.pack()

我不明白为什么这不起作用.我的程序中有另一个图像:

I don't understand why this isn't working. I have another image in my program here:

def Login():
  global W_Menu
  W_Menu = Tk()
  W_Menu.geometry('160x310+600+200')
  W_Menu.title("NSS DB")
  A0 = Canvas(W_Menu, width='160', height='160')
  A0.pack()
  global img
  img = PhotoImage(file="nsslogo.gif")
  A0.create_image(80,80, image=img)

当我在最初调用上述定义后尝试调用它时(例如当我的程序注销时)时,我也遇到了类似的错误,所以我重新调整了窗口,因此窗口只是去图标化而不是再次调用它,然后我不要再次收到错误.然而,我很困惑为什么我现在在前一段代码中出现错误,因为按钮根本不显示它是否第一次被调用.对不起,如果这有点含糊,请询问我是否解释得不够详细.提前致谢.

I also get a similar error when I try to call the above definition after it has already been initially called (for example when my program logs out) so I have readjusted so the window simply deiconifies instead of calling it again, and I do not get the error again. However I am confused as to why I get an error with the former section of code now, as the button simply does not show up whether it is called for the first time or not. Sorry if this is a bit vague, please ask if I have not explained in enough detail. Thanks in advance.

附言我查看了其他有类似问题的线程,但没有一个适用于我.

P.S. I have looked in other threads with similar problems but none apply to me.

推荐答案

好吧,所以你说 login 功能工作一次,然后它不能再次工作.这里的问题可以使用 tk.Toplevel() 而不是 tk.Tk() 来解决,请参阅:为什么 python photoimages 不存在?tkinter.TclError: image "pyimage3";不存在

Ok so you say that the login function works once, then it can't work again. Here the problem can be solved using tk.Toplevel() instead of tk.Tk() see: why python photoimages don't exist? and tkinter.TclError: image "pyimage3" doesn't exist

这些线程提到你不能同时运行两个 Tk() 实例,你必须使用 Toplevel() 代替.

These threads mention how you can't have two instances of Tk() running simultaneously, you have to use Toplevel() instead.

为什么这些主题不适用于您(我认为它们适用...)?但只是一个提示,如果您声明它们不适用于您,然后给出原因,这有助于使您的问题更清楚.此外,当您的问题与特定错误有关时,请添加完整的回溯.

Why did these threads not apply to you (i think they do...)? But just a tip, if you state that they don't apply to you, then give reasons why, it helps make your question clearer. Also, add the full traceback when your question is about a particular error.

希望这会有所帮助.

这篇关于'图像“pyimage2"不存在'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 23:42