Tkinter and PIL: Changing Displayed Image via OptionMenu selection Tkinter and PIL: Changing Displayed Image via OptionMenu selection tkinter tkinter

Tkinter and PIL: Changing Displayed Image via OptionMenu selection


This is a very common bug. In tkinter, you must keep a reference to the image object or it gets garbage collected.

def changeimage():    path.set(cwd + '/img/' + imageVar.get() + '.png')    img = ImageTk.PhotoImage(Image.open(path.get()))    panel.configure(image = img)    panel.img = img # keep a reference