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
#5
#! /usr/bin/env python3

from tkinter import *
from tkinter import ttk

class Picture:
    def __init__(self, parent):
        self.parent = parent
        img = PhotoImage(file='img1.png')
        self.label = ttk.Label(self.parent)
        self.label['image'] = img
        img.image = img
        self.label.pack()

        btn = Button(self.parent, command=self.update, text='Test').pack(side='bottom', pady=50)

    def update(self):
        img = PhotoImage(file='img2.png')
        self.label['image'] = img
        img.image = img

def main():
    root = Tk()
    root.geometry('400x400+50+50')
    Picture(root)
    root.mainloop()

main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
How do I change an image dynamically - by LeeMadeux - Jan-25-2018, 08:49 PM
RE: How do I change an image dynamically - by menator01 - May-28-2020, 10:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter don't change the image DQT 2 1,694 Jul-22-2022, 10:26 AM
Last Post: menator01
  How to dynamically change radiobutton text kenwatts275 2 3,418 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,849 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [WxPython] wx.StaticBitmap change image royer14 4 8,439 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