M
Michele Simionato
I am in the process of learning pygtk and I would like to port
some custom made Tkinter widgets to pygtk, just an exercise.
For instance I have this code:
.. from Tkinter import *
..
.. class AnimatedLabel(Label):
.. def __init__(self, master, text, width=72, maxspc=16, deltat=100,
**kw):
.. self.text = text
.. self.width = width
.. self.maxspc = maxspc
.. self.deltat = deltat
.. self.stringvar = StringVar(master)
.. self.stringvar.set(text)
.. self.stop = False
.. Label.__init__(self, master, textvariable=self.stringvar,
**kw)
..
.. def startAnimation(self, spaces='', addspace=False):
.. if len(spaces) == 0 or len(spaces) == self.maxspc:
.. addspace = not addspace
.. if addspace: # add a space
.. spaces += ' '
.. else: # remove a space
.. spaces = spaces[1:]
.. if not self.stop: # repeat each 100 ms changing spaces and
addspace
..
self.stringvar.set(spaces.join(self.text).center(self.width))
.. self.after(self.deltat, self.startAnimation, spaces,
addspace)
..
.. def stopAnimation(self):
.. self.stop = True
..
..
.. if __name__ == "__main__":
.. t = Tk()
.. t.title('Example')
.. t.config(background='green')
..
.. a = AnimatedLabel(t, text="Hello", fg='blue', bg='green')
.. a.pack()
.. a.startAnimation()
.. t.mainloop()
what's the equivalent of the .after() method in pygtk?
BTW, is there any intro to pygtk thought for Tkinter users?
TIA,
Michele Simionato
some custom made Tkinter widgets to pygtk, just an exercise.
For instance I have this code:
.. from Tkinter import *
..
.. class AnimatedLabel(Label):
.. def __init__(self, master, text, width=72, maxspc=16, deltat=100,
**kw):
.. self.text = text
.. self.width = width
.. self.maxspc = maxspc
.. self.deltat = deltat
.. self.stringvar = StringVar(master)
.. self.stringvar.set(text)
.. self.stop = False
.. Label.__init__(self, master, textvariable=self.stringvar,
**kw)
..
.. def startAnimation(self, spaces='', addspace=False):
.. if len(spaces) == 0 or len(spaces) == self.maxspc:
.. addspace = not addspace
.. if addspace: # add a space
.. spaces += ' '
.. else: # remove a space
.. spaces = spaces[1:]
.. if not self.stop: # repeat each 100 ms changing spaces and
addspace
..
self.stringvar.set(spaces.join(self.text).center(self.width))
.. self.after(self.deltat, self.startAnimation, spaces,
addspace)
..
.. def stopAnimation(self):
.. self.stop = True
..
..
.. if __name__ == "__main__":
.. t = Tk()
.. t.title('Example')
.. t.config(background='green')
..
.. a = AnimatedLabel(t, text="Hello", fg='blue', bg='green')
.. a.pack()
.. a.startAnimation()
.. t.mainloop()
what's the equivalent of the .after() method in pygtk?
BTW, is there any intro to pygtk thought for Tkinter users?
TIA,
Michele Simionato