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
  Tkinter: An image and label are not appearing. emont 7 397 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  tkinter - update/refresh treeview snakes 5 20,525 Dec-02-2023, 07:05 PM
Last Post: aynous19
  help needed running a simple function in pyqt5 diodes 27 8,162 Jan-24-2023, 12:19 PM
Last Post: GetOnData
  [Tkinter] Load image and show in label ko_fal 8 2,918 Oct-25-2022, 09:20 AM
Last Post: ko_fal
  simple tkinter question function call not opening image gr3yali3n 5 3,301 Aug-02-2022, 09:13 PM
Last Post: woooee
  Tkinter won't run my simple function AthertonH 6 3,740 May-03-2022, 02:33 PM
Last Post: deanhystad
  looking for scripts that do simple image display Skaperen 10 4,129 Sep-13-2021, 05:35 PM
Last Post: FullOfHelp
  [Tkinter] image in label not showing? rwahdan 2 7,953 Jun-25-2021, 10:27 AM
Last Post: rwahdan
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 3,672 Apr-23-2021, 07:40 PM
Last Post: JohnT
  tkinter: Image to Label Maryan 10 5,110 Oct-29-2020, 01:48 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

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