Tkinter widget after method Tkinter widget after method tkinter tkinter

Tkinter widget after method


If your goal is to loop through the list, displaying each line at 1500ms intervals, the easiest way is to have a function that does one iteration and then repeats itself using after

Something like this, perhaps:

def read_ref(self, lines):    # remove one item from the list    line = lines.pop(0)    # insert it    self.ref_text.insert("end", line + "\n")    # run again in 1500ms if there's still more work to do    if lines:        self.after(1500, self.read_ref, lines)

Then, call this function exactly once to start the process:

self.read_ref(self, self.reference)

If you want to be able to stop it, you can check for a flag in your function:

def read_ref(self):    ...    if self.reference and not self.stop:        self.after(1500, self.read_ref)

The above code slowly removes items from self.reference. If you don't want that to happen, pass a copy of self.reference when you start so that the function will remove items from a copy of the original data.

self.read_ref(self, self.reference[:])