Python Forum
Refresh image in label after every 1s using simple function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Refresh image in label after every 1s using simple function
#1
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
Reply
#2
you can use the tkinter after method
see: https://effbot.org/tkinterbook/widget.htm
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  looking for scripts that do simple image display Skaperen 10 1,231 Sep-13-2021, 05:35 PM
Last Post: FullOfHelp
  [Tkinter] image in label not showing? rwahdan 2 841 Jun-25-2021, 10:27 AM
Last Post: rwahdan
  tkinter - update/refresh treeview snakes 4 5,270 May-13-2021, 07:10 AM
Last Post: snakes
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 1,501 Apr-23-2021, 07:40 PM
Last Post: JohnT
  tkinter: Image to Label Maryan 10 2,206 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  [Tkinter] Returning always the last image into Label Lucas_Ribeiro 1 1,183 May-08-2020, 05:56 PM
Last Post: deanhystad
  Unable to update or refresh label text in tkinter jenkins43 3 4,262 Jul-24-2019, 02:09 PM
Last Post: Friend
  Simple Button click on image file to create action? jpezz 4 3,992 Mar-27-2019, 10:08 PM
Last Post: jpezz
  Tkinter refresh eduardoforo 4 9,129 Nov-14-2018, 09:35 PM
Last Post: woooee
  [Tkinter] Label doesn't refresh jollydragon 7 4,851 Jul-13-2018, 05:55 AM
Last Post: jollydragon

Forum Jump:

User Panel Messages

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