Python PIL ( image ) module issues

So… I’m trying to make an image vault and i have a whole login page and whatnot but that’s just extra code that isn’t needed currently, What im trying to figure out is why this 26 lines of code dont work.

import customtkinter
import tkinter
import time
user_id = "a"
user_pass = "a"
from PIL import Image
app = customtkinter.CTk()
frame = customtkinter.CTkFrame(master=app,
                               width=250,
                               height=200,
                               corner_radius=10)
def new_page():
    app_1 = customtkinter.CTk()
    frame2 = customtkinter.CTkFrame(master=app_1,
                               width=250,
                               height=200,
                               corner_radius=10)
    my_image = customtkinter.CTkImage(light_image=Image.open('C:/Users/removed/Pictures/Screenshots/1.png'),
                                        dark_image=Image.open('C:/Users/removed/Pictures/Screenshots/1.png'))
    time.sleep(1)
    my_label = customtkinter.CTkLabel(master=app_1,text="",image=my_image)
    my_label.pack(pady=20)
    app_1.mainloop()
button1 = customtkinter.CTkButton(master=app,text="a",command=new_page,width=200, height=35)
button1.place(rely=0.65,relx=0.65)
app.mainloop()

This works fine if i replace

my_label = customtkinter.CTkLabel(master=app_1,text="",image=my_image)

with “app” instead of “app_1”
I’m not sure why this is happening, I’m pretty new.

my_label = customtkinter.CTkLabel(master=app,text="",image=my_image)

^ Works fine but it doesn’t show the image on the other tab
EX:
image
I want it to show the image on the right tab instead of the left one.
if i use

my_label = customtkinter.CTkLabel(master=app_1,text="",image=my_image)

instead of the semi working

my_label = customtkinter.CTkLabel(master=app,text="",image=my_image)

i get this error.

C:\Users\removed>C:/Users/removed/AppData/Local/Programs/Python/Python312/python.exe "c:/Users/removed/Desktop/CustomTkinter Image testing.py"       
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\removed\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1968, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\removed\AppData\Local\Programs\Python\Python312\Lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
    self._command()
  File "c:\Users\removed\Desktop\CustomTkinter Image testing.py", line 21, in new_page
    my_label = customtkinter.CTkLabel(master=app_1,text="",image=my_image)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\removedAppData\Local\Programs\Python\Python312\Lib\site-packages\customtkinter\windows\widgets\ctk_label.py", line 104, in __init__
    self._update_image()
  File "C:\Users\removed\AppData\Local\Programs\Python\Python312\Lib\site-packages\customtkinter\windows\widgets\ctk_label.py", line 141, in _update_image       
    self._label.configure(image=self._image.create_scaled_photo_image(self._get_widget_scaling(),
  File "C:\Usersremoved\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1722, in configure
    return self._configure('configure', cnf, kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\removed\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1712, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist

The problem is that you’re calling CTk() multiple times. It isn’t just a window, it also represents the entire Tcl/Tk interpreter. If you have two, you effectively end up with two different versions of Tk that don’t really know the other exists.

For any additional windows you need to use CTkToplevel instead.

appreciate it! I’ll look into this.

Awesome! Got it to work thanks so much!