Python Forum
[Tkinter] Showing windows after one another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Showing windows after one another
#1
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
Reply


Messages In This Thread
Showing windows after one another - by Ben123 - Feb-22-2024, 05:52 PM
RE: Showing windows after one another - by Ben123 - Feb-23-2024, 01:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020