A Python program loop calls on a tkinter function to create a GUI window. Ideally, each window would be destroyed before control passes out of the tkinter function back to the main Python sequence so that a new window can be created on a clear screen on the next pass of the loop. Instead, what happens is all of the windows that have been created remain onscreen until the Python loop finishes, at which time all of the windows are destroyed. Is there a way to manage the event loop to force each window to be destroyed prior to the return from the tkinter function? (I know that one way to hide the problem would be to define the precise x,y location of the windows, so that each subsequent window covers its predecessor/s, but this would just be a cosmetic fix. I want to know how to correct the underlying problem.) Python 3.5, macOS
import os
from tkinter import *
from tkinter.ttk import *
def display(text):
alert = Tk()
alert.geometry('370x200')
var = StringVar()
var.set(text)
message = Label(alert, textvariable = var, font=('arial',20)).pack(pady=20)
okButton = Button(alert, text = 'OK', command = alert.destroy).place(x=225,y=100)
alert.mainloop()
days = [ 'Mon', 'Tue', 'Wed' ]
for day in days:
message = "Today is " + day
display(message)