What's the Difference Between "Update" and "Update_Idletasks"

What's the difference between update and update_idletasks?

The only difference I see is that update processes all pending events
and calls event callbacks. That's why we should not call update from
within an even callback, I suppose.

You are correct on both accounts.

What are pending events? Events scheduled with after, mostly. And, as you also mentioned in your question, events that trigger a redraw.

The circumstances when you should use update over update_idletasks? Almost never. In all honesty, my pragmatic answer is "never call update unless calling update_idletasks doesn't do enough".

The important thing to remember is that update blocks until all events are processed. In effect, that means you have a mainloop nested inside a mainloop. It's never a good idea to have an infinite loop inside an infinite loop.

If you see examples where one is called after the other, you're looking at bad examples. Honestly, there's absolutely no reason whatsoever to do that. A lot of code I see calls update way more often than it ever should.

How to update a window in Tkinter while using a for loop

You can use <any tkinter object>.update() or <any tkinter object>.update_idletasks(). Both of them update the window/widget and show all changes to the screen. I prefer .update() but if you want to know more about the differences between them look at this.

So in your case try this:

class StartPage(tk.Frame):   
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.label = tk.Label(self, text='EPL Predictions')
self.label.grid(row=0)

NG = tk.Button(self, text='New Game',width = 15, command=lambda: controller.show_frame(SecondPage))
NG.grid(row=1)

Upcoming = tk.Button(self, text='Upcoming Fixtures', width = 15, command=lambda: controller.show_frame(FirstPage))
Upcoming.grid(row=2)

OP = tk.Button(self, text='Odds Progression', width = 15, command=lambda: controller.show_frame(FourthPage))
OP.grid(row=3)

refresh = tk.Button(self, text='Refresh', width = 15, command=lambda: self.refresh_data())
refresh.grid(row=4)

def update_time(self, time_elapsed):
self.label.config("text"=time_elapsed)

def refresh_data(self):
check_time = time.time()
for i in range(10):
time_elapsed = time.time()-check_time
self.update_time(time_elapsed)
self.label.update()


Related Topics



Leave a reply



Submit