In this video we’ll learn how to do Animation for Widgets with CustomTkinter and Python.

How do we move widgets? Maybe you want a menu to slide out when a button is clicked.

Or maybe you want to hide a widget based on a certain user action and want a stylish way to do that.

Animations are the way to do it and I’ll show you how to use them in this video.

Python Code: ctk_animations.py
(Github Code)

from tkinter import *
import customtkinter

# Set the theme and color options
customtkinter.set_appearance_mode("dark")  # Modes: system (default), light, dark
customtkinter.set_default_color_theme("dark-blue")  # Themes: blue (default), dark-blue, green

#root = Tk()
root = customtkinter.CTk()

root.title('Tkinter.com - CustomTkinter Widget Animations')
root.iconbitmap('images/codemy.ico')
root.geometry('700x450')

global my_y
my_y = 450/2+350

def up():
	global my_y
	my_y -= 20
	if my_y >= 195:
		my_text.place(x=700/2, y=my_y, anchor='center')
		up_button.configure(text=my_y)
		root.after(5, up)

def down():
	global my_y
	my_y += 20
	if my_y <= 750:
		my_text.place(x=700/2, y=my_y, anchor='center')
		up_button.configure(text=my_y)
		root.after(5, down)


#Frame
my_frame = customtkinter.CTkFrame(root)
my_frame.pack(pady=20)

# Buttons
up_button = customtkinter.CTkButton(my_frame, text="Up", command=up)
up_button.grid(row=0, column=0, padx=10)

down_button = customtkinter.CTkButton(my_frame, text="Down", command=down)
down_button.grid(row=0, column=1, padx=10)

# Text Box 
my_text = customtkinter.CTkTextbox(root, width=400, height=200)
my_text.place(x=700/2, y=my_y, anchor='center')



root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

1 comment

Your email address will not be published. Required fields are marked *

  • I’ve been watching your tkinter videos on YouTube. They are awesome and super helpful! Thank you for what you are doing. I would love a copy of the widgets reference book if you are still emailing free copies.

    Thanks again!

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...