pythonuser-interfacetkinterprojectphotoimage

How to display an image in a specific tkinter window using PhotoImage?


I have two running tkinter windows but I want only one specific window to display the image but I am not able to achieve this. I tried to specify the master in the Label statement but python shows an error which says "image pyimage1 doesn't exist" Please help

import tkinter as tk
from PIL import Image, ImageTk

a=tk.Tk()
a.geometry('800x500+275+100')
a.title('HOME PAGE')

c=tk.Tk()
c.geometry('800x500+275+100')
c.title('PROFILE')

load=Image.open('untitled.png')
render=ImageTk.PhotoImage(load)
img=tk.Label(c,image=render)
img.pack()

a.mainloop()
c.mainloop() 

Solution

  • If you want a second screen use tk.Toplevel and remove c.mainloop

    a=tk.Tk()
    a.geometry('800x500+275+100')
    a.title('HOME PAGE')
    
    c=tk.Toplevel()
    c.geometry('800x500+275+100')
    c.title('PROFILE')
    
    load=Image.open('untitled.png')
    render=ImageTk.PhotoImage(load)
    img=tk.Label(c,image=render)
    img.pack()
    
    a.mainloop()