Hi I have a problem with loading an image to a new window in tkinter. Here is my code to open new widnow and it opens new window, but it doesn't open a new image. I can load images to my root window without problem as you can see below, but I also need to load a new/another image to a new window.
def open_new_image(self):
new_image_window = Toplevel(self.root)
new_image_window.title('New window')
new_image_window.geometry("700x500")
lbl2 = Label(new_image_window)
lbl2.pack()
def onClick():
img = self.load_image_internal()
# new_image = ImageTk.PhotoImage(Image.open(path))
lbl2.configure(image=img)
print("dsdsds")
new_image_window.update()
load_image = tk.Button(new_image_window, text='Load image',
command=onClick)
load_image.pack()
new_image_window.mainloop()
Here is my method for loading an image
def load_image_internal(self):
path = os.getcwd ()
filename = filedialog.askopenfilename(initialdir=path,
title="Select image",
filetypes=[
("image", ".png"),
("image", ".jpg"),
])
return ImageTk.PhotoImage(Image.open(filename))
I have no idea why it doesn't work. I have tried to look for answer here, but all replies are for loading image to the main/root window which I already have.
I have tried, but I am stuck how to make the load image button work.