Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'image "pyimage2" doesn't exist'?

Tags:

python

tkinter

This is where the error is found:

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.

like image 501
user3112327 Avatar asked Sep 29 '14 10:09

user3112327


1 Answers

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

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.

Hope this helps a bit.

like image 165
W1ll1amvl Avatar answered Oct 21 '22 10:10

W1ll1amvl