8

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.

1
  • Show the full error/traceback. Commented Sep 29, 2014 at 11:43

5 Answers 5

22

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, works really well! I am very new to coding so just an error on my part - they did apply to me. Hopefully next time this won't happen :)
4

You can add a master parameter

backbuttonimg = PhotoImage(file="backbutton.gif",master=W_Menu)

Comments

1

Adding this for anyone who has tried the above with no success. If you have an erroneous path when running the script in some environments the path to the file is retained. I commented out everything from where I first use PhotoImage up to the window mainloop, run the script, close resulting gui, uncomment the code, run, and it shows the image as expected.

Comments

0

Here Cledia I am also facing this error. And when I use Toplevel instead of To, it is working well I suggest you to use TopleToplevel

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
0

Use tk.Toplevel() instead of tk.Tk() So its will work because the python coding library tkinter it doesnt make any sens if you make two windows working sametime with the tk.Tk() so you can use the toplevel() to open multiwindows in the same time !! Hope it's Helpful

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.