0

If I created Tkinter window with some text that filled the whole window and now wanted to replace the window with a new text, is there a way to refresh the window?

For Example:

a= 100
win= Tk()
win.geometry("500x300")
while a > 0:
if a%2 == 0:
lbl = Label (win, bg = "purple")
lbl.pack()
else:
lbl = Label (win, bg = "blue")
lbl.pack()
a= x-1
The problem with this code is that the Tkinter window does not refresh and just provides the end result instead of showing the windows changing colors. Thanks for the help!

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by pyTony
0

If I created Tkinter window with some text that filled the whole window and now wanted to replace the window with a new text, is there a way to refresh the window?

For Example:

a= 100
win= Tk()
win.geometry("500x300")
while a > 0:
if a%2 == 0:
lbl = Label (win, bg = "purple")
lbl.pack()
else:
lbl = Label (win, bg = "blue")
lbl.pack()
a= x-1
The problem with this code is that the Tkinter window does not refresh and just provides the end result instead of showing the windows changing colors. Thanks for the help!

Do you mean like this?

from Tkinter import *

def change(a=0):
    print a, ## debug
    lbl.config(bg = "blue" if a & 1 else "purple")
    lbl.after(400,change, a ^ 1 )

if __name__ == '__main__':
    win= Tk() 
    win.geometry("500x300")
    lbl = Label (win)
    lbl.pack(expand=YES, fill=BOTH)
    change()
    
    win.mainloop()

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.