Python Forum
Refresh image in label after every 1s using simple function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Refresh image in label after every 1s using simple function (/thread-20111.html)



Refresh image in label after every 1s using simple function - jenkins43 - Jul-28-2019

I am trying to refresh the Label Image after every 1s I have created one class in which only one time I 'll click on the button to display the image and after that, it will refresh after every second but unable to make that work

Earlier I was trying to make it work with canvas but it wasn't helping me out by showing it through label but was able to refresh using

self.canvas.after(100, self.loopCap)
but now in a label widget, I am not able to understand how refreshing the label every time

Code for is mentioned below:
class PageTwo(tk.Frame):
    def loopCap(self):
        # self.label = Label(self.master, image=self.img, textvariable=self.text)
        self.img = Image.open("img.jpg")
        self.label = ImageTk.PhotoImage(self.img)
        tk.Label(self, image=self.label).pack()
        print("updated")

    def __init__(self, master):
        tk.Frame.__init__(self, master,bg='powder blue')
        self.master.geometry('1350x750+0+0')
        self.master.config(bg='powder blue')
        tk.Button(self, text="Return to start page",
                  command=self.loopCap).pack()
        print("Load")
Suggestions will be much appreciated


RE: Refresh image in label after every 1s using simple function - Larz60+ - Jul-28-2019

you can use the tkinter after method
see: https://effbot.org/tkinterbook/widget.htm