Within my code script I have a window open up that should display a image of a creeper head. Whenever I try running the code, I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 1967, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/customtkinter/windows/widgets/ctk_button.py", line 554, in _clicked
self._command()
File "/Users/*me*/Desktop/Python/Computer Science 20 Stuff/Cookie Clicker Game/main.py", line 380, in info_button_callback
new_window()
File "/Users/*me*/Desktop/Python/Computer Science 20 Stuff/Cookie Clicker Game/main.py", line 143, in new_window
creeper_label = customtkinter.CTkLabel(
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/customtkinter/windows/widgets/ctk_label.py", line 104, in __init__
self._update_image()
File "/opt/homebrew/lib/python3.12/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 "/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 1721, in configure
return self._configure('configure', cnf, kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 1711, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage26" doesn't exist
I have verified that it is within the same file path as the python file, I have changed the image with another image i was able to load in for a different purpose within my code, and I have checked the file extension and it is appropriate.
Code (short form):
import customtkinter
from PIL import Image
creeper_bg = customtkinter.CTkImage(
dark_image=Image.open("creeper_bg.png"), size=(70, 70))
def main_loop():
* Main stuff here*
def back_right_button_callback():
* back_right_button_callback stuff here *
def info_button_callback():
info_window = customtkinter.CTk()
w = 300
h = 200
ws = info_window.winfo_screenwidth()
hs = info_window.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
info_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
info_window.resizable(False, False)
creeper_label = customtkinter.CTkLabel(
info_window, width=70, height=70, image=creeper_bg, text="", corner_radius=0, fg_color="transparent", bg_color="transparent")
creeper_label.place(x=10, y=100, anchor="w")
info_window.mainloop()
info_button = customtkinter.CTkButton(main, image=info_bg, text="", width=40, height=40, fg_color="transparent", bg_color="transparent", corner_radius=0, border_width=0, border_spacing=0, hover=True, hover_color="#868686", command=info_button_callback)
info_button.place(x=46, y=576, anchor="w")
Paste Bin: https://pastebin.com/WxW4ybKA
figured out what was wrong, i just needed for info_window
to be info_window = customtkinter.CTkToplevel()
instead of info_window = customtkinter.CTk()