0

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() 
Bitopan
  • 3
  • 3
  • 2
    You should use `Toplevel()` for `c`: `c = tk.Toplevel()`. And remove `c.mainloop()` as well. – acw1668 Nov 13 '20 at 08:16
  • 1
    See [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – martineau Nov 13 '20 at 08:43
  • Apart from all this, if you still wish to keep two instance of `Tk()` then change your `render` to `render=ImageTk.PhotoImage(image=load,master=c)`, but still more changes might be needed later on to make the whole app work properly – Delrius Euphoria Nov 13 '20 at 10:37
  • oh thanks @acw1668 it works now – Bitopan Nov 13 '20 at 19:03
  • 1
    @CoolCloud I tried, it's working thanks – Bitopan Nov 13 '20 at 19:03

1 Answers1

1

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()
coderoftheday
  • 1,987
  • 4
  • 7
  • 21