Refresh image in Tkinter window
Here is a solution that uses Tkinter's Tk.after
function, which schedules future calls to functions. If you replace everything after your fetch_image
definition with the snipped below, you'll get the behavior you described:
root = Tkinter.Tk()label = Tkinter.Label(root)label.pack()img = Nonetkimg = [None] # This, or something like it, is necessary because if you do not keep a reference to PhotoImage instances, they get garbage collected.delay = 500 # in millisecondsdef loopCapture(): print "capturing"# img = fetch_image(URL,USERNAME,PASSWORD) img = Image.new('1', (100, 100), 0) tkimg[0] = ImageTk.PhotoImage(img) label.config(image=tkimg[0]) root.update_idletasks() root.after(delay, loopCapture)loopCapture()root.mainloop()