A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-list/2001-April/085622.html below:

Animation with Tk

Animation with TkPoD pod at internode.on.net
Sat Apr 21 09:55:41 EDT 2001
Nick Perkins wrote:
> 
> How can I run a timing loop in a Tk app?
> I would like to use the Tk.Canvas widget to try some simple animation.
> It has some cool features.
> I need to have an animation loop, but also have working buttons, etc,
> which means running the tk mainloop.
> 
> I have tried to use the sched module, sheduling a function that
> updates the canvas and then reschedules itself.
> However, the run() method does not return immediately, which would be
> nice, it just goes to sleep.
> Consequently, I can not seem to get Tk.mainloop() to run
> at the same time as a scheduler.
> Since I am using Windows, I don't think I can fork().
> 
> How can I run a Tk mainloop() and also an event sheduler, or
> some other type of timing loop?

The simplest way may be using the widget.after() method.

class AppWindow:
  def __init__(self):
    self.root = Tk()
    blah blah...
    self.root.after(100,self.after_callback)
    self.root.mainloop()

  def after_callback(self):
    do_animation_stuff()
    self.root.after(100,self.after_callback)

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4