forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anim.py
56 lines (47 loc) · 1.04 KB
/
anim.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from tkinter import *
root = Tk()
root.title('Codemy.com - Simple Button Animation')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("400x300")
#define some variables
count = 0
size = 26
pos = 100
# Contract the button
def contract():
global count, size, pos
if count <= 10 and count > 0:
size -= 2
# Configure button font size
my_button.config(font=("Helvetica", size))
# Change button position
my_button.pack_configure(pady=pos)
# decrease the count by 1
count -= 1
pos -= 20
# Set a timer
root.after(100, contract)
# Expand the button
def expand():
global count, size, pos
if count < 10:
size += 2
# Configure button font size
my_button.config(font=("Helvetica", size))
# Change button position
my_button.pack_configure(pady=pos)
# Increase the count by 1
count += 1
pos += 20
# Set the timer
root.after(100, expand)
elif count == 10:
contract()
# Create a button
my_button = Button(root,
text="Click Me!",
command=expand,
font=("Helvetica", 24),
fg="red")
my_button.pack(pady=100)
root.mainloop()