Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_simple_button_animation.py
- from tkinter import *
- root = Tk()
- root.title('Simple Button Animation')
- root.geometry("400x300")
- #define some variables
- count = 0
- size = 26
- pos = 100
- # Contract the button
- def contract():
- global count, size, pos
- if count:
- 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 += 2
- # Set a timer
- root.after(4, contract)
- # Expand the button
- def expand():
- global count, size, pos
- if count < 15:
- 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 -= 2
- # Set the timer
- root.after(2, expand)
- else:
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement