0

Every time I'm getting this error: _tkinter.TclError: image "pyimage2" doesn't exist

When I want to execute this code:

self.frame1 = customtkinter.CTkFrame(self)
self.frame1.pack(fill="both", padx=20, pady=20)
book_image = customtkinter.CTkImage(Image.open(self.thumbnail_path))
image_label = customtkinter.CTkLabel(self.frame1, image=book_image, text="")
image_label.pack(side=customtkinter.LEFT, padx=10, pady=10)

The path is here:

self.filename = f"{random.randint(10000, 100000)}.png"
self.thumbnail_path = os.path.join(cache_dir, self.filename)
self.cache_file = os.path.join(cache_dir, self.filename)

if not os.path.exists(self.cache_file):
    urllib.request.urlretrieve(self.thumbnail, self.cache_file)

The image should be placed in a CTkToplevel (via a class) which is called by the root window. If it's helpful(?); I'm using a Mac

1
  • The error is most likely caused by multiple instances of Tk or customtkinter.CTk. It is better to provide a minimal reproducible example in order to identify the cause. Commented Oct 25, 2024 at 8:11

1 Answer 1

1

To add to acw1668's comment, the error could be caused by running more than one instance of Tk.

Also have a look at these questions image-pyimage2-doesnt-exist and tkinter-tclerror-image-pyimage3-doesnt-exist. They seem to have a similar problem.

If this is the case the issue is most likely solved by running one instance as Toplevel() instead of Tk()

If that doesn't solve the problem, we would need to see more of your implementation so we can reproduce the issue.

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

2 Comments

My implementation is like this: Tk() -> Tk() -> Toplevel()
I changed it to: Tk() -> Toplevel() -> Toplevel() and now it works, thanks!

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.