Python Forum
[Tkinter] How do I change an image dynamically
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How do I change an image dynamically
#1
I am trying to dynamically change a displayed picture to another picture on a GUI.
I have tried various suggested ways seen on websites and none have worked this far.
What am I doing wrong?

from tkinter import *
from tkinter import ttk

def TestLogic():
    stgImg = PhotoImage(file="Stage1.gif")
    label=ttk.Label(root, image=stgImg)
    label.image = stgImg
    return

root = Tk()

root.geometry('1010x740+200+200')

stgImg = PhotoImage(file="Stage0.gif")
label=ttk.Label(root, image=stgImg)
label.place(x=400, y=400)

testBtn=ttk.Button(root, text="TEST", command=TestLogic)
testBtn.place(x=400, y=200)
root.mainloop()
The first image is displayed just fine. When I press the button, nothing happens.

Thanks...
Reply


Messages In This Thread
How do I change an image dynamically - by LeeMadeux - Jan-25-2018, 08:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter don't change the image DQT 2 1,678 Jul-22-2022, 10:26 AM
Last Post: menator01
  How to dynamically change radiobutton text kenwatts275 2 3,405 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,828 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [WxPython] wx.StaticBitmap change image royer14 4 8,414 Jul-02-2018, 02:35 PM
Last Post: royer14

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020