This code of program is not running and showing error image "pyimage2" doesn't exist
import tkinter
from PIL import ImageTk, Image
def imagine():
window1 = tkinter.Tk()
window1.geometry("1000x300")
img = ImageTk.PhotoImage(Image.open("1.jpg"))
label1= tkinter.Label(window1, image = img)
label1.place(x=10,y=2)
window = tkinter.Tk()
window.geometry("1000x300")
img = ImageTk.PhotoImage(Image.open("1.jpg"))
label1= tkinter.Label(window, image = img)
label1.place(x=10,y=2)
b1 = tkinter.Button(window,text="E",width=50,command=imagine ).place(x=100,y=2)
i want image on window1 also
In the "imagine" you are trying to create a new instance of
Tk()which already exists. (we can only have a single instance of Tk) For an additional window, create instance ofToplevel().I tested your code with fix and new window open without any error, but the image still doesn't appear.
To fix this, I passed
imgas a parameter using the lambda function.