0

I tried to make a Python Tkinter window which opens another Tkinter Window but for some reason in the second window no image shows up and this error message is there:

image "pyimage1" doesn't exist

How can I fix this?

import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import time

def startnew():
    imagetest = Image.open("test.png").resize((1000, 620))
    phototest = ImageTk.PhotoImage(imagetest)
    test = tk.Tk()
    test.geometry("1000x620")
    testlabel = ttk.Label(test, image=phototest)
    testlabel.place(x=-2, y=-2)

microsoft = tk.Tk()
microsoft.geometry("1000x620")

microlabel = ttk.Label(microsoft)
microabel.place(x=-2, y=-2)

button = tk.Button(microsoft, text="plzhelp", command=startnew)
button.place(x=100, y=100)

tk.mainloop()

I know there are posts with the same error but I cant understand them because their projects are complex

martineau
  • 119,623
  • 25
  • 170
  • 301
yletz xyz
  • 1
  • 2
  • What don't you understand about the accepted answer to the linked duplicate? The code snippets involved do not seem that complex to me. Regardless, here a hint: You need to add a reference to the `phototest` image in the `startnew()` function. – martineau Feb 21 '22 at 19:23
  • The duplicate this was closed for is certainly *a* problem with this code, but it's not the only problem. Multiple calls to `Tk()` cause problems like this; you need to use `Toplevel()` instead to create additional windows. – jasonharper Feb 21 '22 at 19:30

0 Answers0