I have started to work with Tkinter recently and stuck here. I want to load an image after clicking a Button. The button will generate a text as well as an image below it.
from tkinter import *
from PIL import ImageTk, Image
main_window = Tk()
main_window.geometry('400x400')
main_window.title("A OR B[enter image description here][1]")
frame = Frame(main_window)
def show():
if clicked.get() == 'A':
Label(main_window,text = 'A SELECTED',).pack()
img = ImageTk.PhotoImage(Image.open('l.png'))
panel = Label(main_window,image = img)
panel.pack()
elif clicked.get() == 'B':
Label(main_window,text = 'B SELECTED',).pack()
img = ImageTk.PhotoImage(Image.open('g.png'))
panel = Label(main_window,image = img)
panel.pack()
clicked = StringVar()
clicked.set('SELECT A or B ')
drop = OptionMenu(main_window,clicked,*options).pack()
Button(main_window, text='GENERATE',fg='white',bg='blue',command = show).pack()
main_window.mainloop()
I am getting the text but not the image loaded in tkinter window.