import canvasdraw_tags import _threadtime class canvaseventsdemo(canvasdraw_tags canvaseventsdemo)def moveem(selftag)for in range( )for (diffxdiffyin [(+ )( + )(- )( - )]self canvas move(tagdiffxdiffytime sleep( pause this thread only def moveinsquares(selftag)_thread start_new_thread(self moveem(tag,)if __name__ ='__main__'canvaseventsdemo(mainloop(this version lets you move shapes at the same timejust like example - but this time it' reflection of threads running in parallel in factthis uses the same scheme as the first time sleep version herethoughthere is more than one active thread of controlso move handlers can overlap in time--time sleep blocks only the calling threadnot the program at large this example works on windows todaybut it failed on linux at one point in this book' lifetime--the screen was not updated as threads changed itso you couldn' see any changes until later gui events the usual rule of thumb about avoiding gui updates in spawned threads laid out earlier still holds true it is usually safer to have your threads do number crunching only and let the main thread (the one that built the guihandle any screen updates even under this modelthoughthe main thread can still use after event loops like that of example - to watch for results from worker threads to appear without being blocked while waiting (more on this in the next section and parts of this story are implementation details prone to change over timeand it' not impossible that gui updates in threads may be better supported by tkinter in the futureso be sure to explore the state of threading in future releases for more details other animation topics we'll revisit animation in ' pydraw examplethereall three of the techniques we just met--sleepstimersand threads--will be resurrected to move shapestextand photos to arbitrary spots on canvas marked with mouse click and although the canvas widget' absolute coordinate system makes it the workhorse of most nontrivial animationstkinter animation in general is limited mostly by your imagination in closinghere are few more words on the topic to hint at the possibilities time toolsthreadsand animation