[Tutor] Tkinter and after() method

Phil phillor9 at gmail.com
Fri Jan 27 01:10:08 EST 2023


It's been quite some time since I've played with Tkinter and despite 
searching the Internet for most of the day I seem to have hit a dead-end.

I'm trying to put a pause within a for-loop as follows:

def my_function(self):
     for i in range(5):
         do something here eg. print(i)
         self.after(1000)

Instead of printing i every second my_function is delayed for 5 seconds.

To try to get some understanding of what's required I tried this:

self.r = 31

self.abc()
self.print_count()
self.after(1000, self.print_count()

def abc(self):
     self.r += 1
     print(self.r)

def print_count(self)
     self.abc()
     self.after(1000, self.print_count()

This prints 32 - 1025, without a one second delay, before the programme 
ends with: "RecursionError: maximum recursion depth exceeded while 
calling a Python object".

Although I haven't tried it I suspect that if I used a label to display 
the count rather than a print statement then I might not see a recursion 
error.

I probably should try that before posting this but I've got a splitting 
headache and it hasn't helped with my original delay within a for_loop 
problem.

-- 
Regards,
Phil



More information about the Tutor mailing list