Tkinter.Tclerror: Image "Pyimage3" Doesn't Exist

tkinter.TclError: image "pyimage3" doesn't exist

I found the issue so figured I'd answer myself for anyone who has this issue in the future.

When the wlcm_scrn runs procedurely it is the only window that exists at that point in time, and so it can use tkinter.Tk(). The error arises because the button that calls the function is itself sitting in an active window that is also running as Tkinter.Tk(). So when Python/Tkinter tries to build wlcm_scrn from the button, it's essentially trying to create two windows under root and falling over.

The solution:

Changing line...

wlcm_scrn = tkinter.Tk()

to this...

wlcm_scrn = tkinter.Toplevel()

...stops the error, and the image shows.

I personally am going to have two instances of the function. One called procedurely under Tk(), and one called within the application under TopLevel().

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

tkinter uses tcl different interpreters for each Tk() window. Each interpreter has its own memory. All of the children of the window are managed by the same tcl interpreter. When you don't pass in the master parameter tkinter uses the first created tcl interpreter.

Consider this example:

import tkinter as tk

root_1 = tk.Tk() # Note this is the default root now
root_2 = tk.Tk()

label_1 = tk.Label(text="Hi") # By default `master=root_1`
label_1.pack()

tk_img = tk.PhotoImage(file="...") # By default `master=root_1`
label_2 = tk.Label(root_2, image=tk_img) # We are trying to use something that doesn't exist in this tcl interpreter.
label_2.pack()

Note that we haven't passed in a master for label_1 and tk_img. The first argument of tkinter widgets are usually the master so for label_2 the master is root_2.

Tkinter can't create a widget without a master as the widget must live in a tcl interpreter so it tries to guess which tcl interpreter it should use (always the first one that has been created). Therefore, the master for label_1 and tk_img will be root_1. So when we tell the second interpreter that we want it to use the variable tk_img (on this line label_2 = tk.Label(root_2, image=tk_img)), it fails as the second interpreter (for the second window) doesn't know about the other interpreter.

'image "pyimage2" doesn't exist'?

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.



Related Topics



Leave a reply



Submit