Python Forum

Full Version: Refresh image in label after every 1s using simple function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
you can use the tkinter after method
see: https://effbot.org/tkinterbook/widget.htm