I am trying to make a pre-defined GUI workflow (i.e., pipeline) using the after
method of Tkinter, but it does not work and I am confused.
As a minimal example, I have created this simple GUI:
from tkinter import *
class example:
global frame, rect, text
def __init__(self):
self.root = Tk()
self.initialize()
self.workflow()
self.root.mainloop()
def initialize(self):
global frame, rect, text
# frame
frame = Canvas(self.root, width=500, height=500, bd=0, highlightthickness=0, relief='ridge')
frame.grid(row=0, column=0)
# rectangle
rect = frame.create_rectangle(20, 20, 400, 350, fill='blue')
# text
text = frame.create_text(250, 250, text='FIRST...', fill='#ffff00', font=("Purisa", 20, "bold"))
def change_message(self, new_message):
global frame, text
frame.itemconfig(text, text=new_message)
def workflow(self):
global frame, rect, text
self.root.after(2000, self.change_message("SECOND..."))
self.root.after(4000, self.change_message("END"))
myExample = example()
The aim is to follow the pipeline that is specified in the workflow
method, which is the following:
- 1st: The message shows the text "FIRST..." when the application is run
- 2nd: After 2 seconds, the text changes and shows "SECOND..."
- 3rd: After 4 seconds, the text changes again and shows "END"
But, when I run this example, the GUI waits 4 seconds to show up, and displays the final "END" message, without plotting the previous changes...
What am I doing wrong?
Thanks in advance