[Tutor] Tkinter and Animation

jfouhy at paradise.net.nz jfouhy at paradise.net.nz
Wed Apr 27 01:22:40 CEST 2005


Quoting Jeremiah Rushton <jeremiah.rushton at gmail.com>:

> In a program that I'm writing in Tkinter, I wanted to know how to
> animate objects. I have three buttons in the beginnig, all in the 
> center. I wanted to know how to, when the user clicks one of them,
> make them small and move to a top corner and then have a text box 
> appear where they were.

Do you actually want to _animate_ them (ie: have the buttons visually shrink and
move across the screen), or do you just want them to vanish and appear in the
new place?

In Tkinter, placing an object on the screen (using grid or pack) is distinct
from creating the object.  You can use .grid_forget() or .pack_forget() to
ungrid or unpack an object, so that it is not displayed, but it still exists. 
And/or you can just recall grid/pack with different arguments.

eg:

>>> from Tkinter import *
>>> tk = Tk()
>>> b = Button(tk, text='Make')
>>> current = [0]
>>> def make():
...  c = current[0]
...  Label(tk, text='Entry %d' % c).grid(row=c, column=0)
...  Entry(tk).grid(row=c, column=1)
...  b.grid(row=c+1, column=1)
...  current[0] = c + 1
...
>>> b.config(command=make)
>>> b.grid(row=0, column=1)

-- 
John.


More information about the Tutor mailing list