Controlling Display Updates (Advanced)

Usually, the visual display of a GraphWin is updated each time the draw method is called on an object, or an object's visible state is changed in some way. However, under some circumstances, for example when using the graphics library inside some interactive shells, it may be necessary to force the window to update in order for changes to be seen. The update() function is provided to do this.

update()
Causes any pending graphics operations to be carried out and the results displayed.

For efficiency reasons, it is sometimes desirable to turn off the automatic updating of a window every time one of the objects changes. For example, in an animation, you might want to change the appearance of multiple objects before showing the next ``frame'' of the animation. The GraphWin constructor includes a special extra parameter called autoflush that controls this automatic updating. By default, autoflush is on when a window is created. To turn it off, the autoflush parameter should be set to False, like this:

win = GraphWin("My Animation", 400, 400, autoflush=False)
Now changes to the objects in win will only be shown when the graphics system has some idle time or when the changes are forced by a call to update().

John Zelle 2010-08-29