This works as expected:
img = tk.PhotoImage(file="gfx/button.png")
btn1 = tk.Button(root,image=img,width=wid,height=hgt)
btn1.grid(column=0,row=0,padx=pad_x,pady=pad_y)`
btn2 = tk.Button(root,image=img,width=wid,height=hgt)
btn2.grid(column=1,row=0,padx=pad_x,pady=pad_y)
This does not - neither button gets an image:
btn1 = tk.Button(root,image=tk.PhotoImage(file="gfx/button.png"),width=wid,height=hgt)
btn1.grid(column=0,row=0,padx=pad_x,pady=pad_y)
btn2 = tk.Button(root,image=tk.PhotoImage(file="gfx/button_active.png"),width=wid,height=hgt)
btn2.grid(column=1,row=0,padx=pad_x,pady=pad_y)
This works as expected:
img = tk.PhotoImage(file="gfx/button.png")
btn1 = tk.Button(root,image=img,width=wid,height=hgt)
btn1.grid(column=0,row=0,padx=pad_x,pady=pad_y)
img2 = tk.PhotoImage(file="gfx/button_active.png")
btn2 = tk.Button(root,image=img2,width=wid,height=hgt)
btn2.grid(column=1,row=0,padx=pad_x,pady=pad_y)
This does not - second button gets correct image, first button gets no image:
img = tk.PhotoImage(file="gfx/button.png")
btn1 = tk.Button(root,image=img,width=wid,height=hgt)
btn1.grid(column=0,row=0,padx=pad_x,pady=pad_y)
img = tk.PhotoImage(file="gfx/button_active.png")
btn2 = tk.Button(root,image=img,width=wid,height=hgt)
btn2.grid(column=1,row=0,padx=pad_x,pady=pad_y)
I am particularly confused by the second example.
Clarification:
Why does this work:
img = tk.PhotoImage(file="gfx/button.png")
btn1 = tk.Button(root,image=img)
but this does not:
btn1 = tk.Button(root,image=tk.PhotoImage(file="gfx/button.png"))