Feb-22-2024, 05:52 PM
import tkinter as tk from PIL import Image, ImageTk class Class1(): def __init__(self) -> None: self.root = tk.Tk() self.root.geometry('800x800') def RunWindow(self): self.root.mainloop() def CloseWindow(self): self.root.quit() def ShowWindow(self): image_og = Image.open('IMG_0126.jpg').resize((500, 350)) self.image_tk = ImageTk.PhotoImage(image_og) PicLabel = tk.Label(self.root, image = self.image_tk) PicLabel.place(relx = 0.1, rely = 0.1) nextButton = tk.Button(self.root,text = 'next', command = self.CloseWindow) nextButton.place(relx = 0.7, rely = 0.8) test = Class1() test.ShowWindow() test.RunWindow() print('yes') test1 = Class1() test1.ShowWindow() test1.RunWindow()When this is run it comes up with an error message saying
Traceback (most recent call last):
File "DocumentLocation", line 31, in <module>
test1.ShowWindow()
File "DocumentLocation", line 20, in ShowWindow
PicLabel = tk.Label(self.root, image = self.image_tk)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 3214, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 2628, in __init__
self.tk.call(
_tkinter.TclError: image "pyimage2" doesn't exist
I don't understand what the issue is? any help would be appreciated