Python Forum
[Tkinter] Tk window not displaying until loop has completed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tk window not displaying until loop has completed
#1
Hi, I'm new to python and Tkinter (as in two days in!), so appreciate this may be a pretty obvious mistake I'm making. Why is it that if I have a loop(s) in my code that the Tk window doesn't display until the loop(s) has gone through all it's iterations. What I want is for the window to display at the start so that I can then view the result of each iteration in the window. Here's a small sample program to show what I mean. If you run it yourself you'll see the lag before the window opens.

from tkinter import *

root = Tk()

for column in range (0, 50):
    
    for row in range (0, 40):
        
        #calculate next number from row and column
        number = row+(column*40)
        #create label
        myLabel = Label(root, text=str(number))
        #display label
        myLabel.grid(row=row, column=column)
    
root.mainloop()
Reply


Messages In This Thread
Tk window not displaying until loop has completed - by Ganga - Aug-09-2021, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 759 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Trying to make random image loop in Tk window using python Jediguy18 1 3,278 Dec-30-2020, 04:56 AM
Last Post: deanhystad
  Displaying various layouts in a single window arbiel 6 4,206 Nov-08-2020, 09:21 PM
Last Post: arbiel
  tkinter window and turtle window error 1885 3 6,855 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,260 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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