blob: 5743a7067a554b49413113b3e3a7a24e2e5c2018 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from Tkinter import *
class Spacer(object):
nspaces = 0
action = "increment"
MAXSPACES = 10
def manage_spaces(self):
if self.action == "increment":
self.nspaces += 1
elif self.action == "decrement":
self.nspaces -= 1
if self.nspaces > self.MAXSPACES:
self.action = "decrement"
if self.nspaces < 0:
self.action = "increment"
return " " * self.nspaces
spacer = Spacer()
class AnimatedLabel(Label):
DELTA_T = 100
def __init__(self, master, **kw):
Label.__init__(self, master, **kw)
self.master = master
self.word = self.cget("text")
def start_animation(self):
spaces = spacer.manage_spaces()
centered_word = spaces.join(self.word).center(50)
self.config(text=centered_word)
self.master.after(self.DELTA_T, self.start_animation)
if __name__ == "__main__":
root = Tk()
lab = AnimatedLabel(root, text="Anime")
lab.pack()
lab.start_animation()
root.mainloop()
|