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
Pythonic Way to Create Union of All Values Contained in Multiple Lists
How to Get Rid of Beautifulsoup User Warning
Why Is the Borg Pattern Better Than the Singleton Pattern in Python
Writing Utf-8 String to MySQL with Python
Keras Sequential Model Input Layer
Can Pandas Groupby Aggregate into a List, Rather Than Sum, Mean, etc
How to Access a File's Properties on Windows
Rreplace - How to Replace the Last Occurrence of an Expression in a String
How to Make Built-In Containers (Sets, Dicts, Lists) Thread Safe
Parsing .Properties File in Python
How to Use a Custom Comparison Function in Python 3
Adding Labels in X Y Scatter Plot with Seaborn
Scikit-Learn Dbscan Memory Usage
Matplotlib Scatterplot with Legend
What Is the Most Compatible Way to Install Python Modules on a MAC
How to Remove the Top and Right Axis in Matplotlib
Get the Position of the Largest Value in a Multi-Dimensional Numpy Array