I have a set of code
photo = PhotoImage(file = "computer.png")
label = Label(root, image = photo)
label.pack()
When it is defined in the main program, it executes. When it is defined in a function as
def callback():
photo = PhotoImage(file = "computer.png")
label = Label(root, image = photo)
label.pack()
print ("click!")
then only click! was printed on python shell and nothing else. This code is to display an image on windows form developed using Tkinter
Call to the function was earlier made with menu command but there was no output than through a button with same result
This is inline code
root = Tk()
root.title('View')
root.geometry('600x400')
photo = PhotoImage(file = "computer.png")
label = Label(root, image = photo)
label.pack()
This is the function
def callback():
photo = PhotoImage(file = "computer.png")
label = Label(root, image = photo)
label.pack()
print ("click!")
call through menu command
viewmenu.add_command(label="1:1 Zoom", command=About)
call through button click
b = Button(root, text="OK", command=callback)
b.pack()
The expected result is to display the image on Tkinter winform and the actual result is nothing just printing click! on python shell