Affichage des articles dont le libellé est tkinter. Afficher tous les articles
Affichage des articles dont le libellé est tkinter. Afficher tous les articles

Python Tkinter Sonic Wave Animation

How to Create a Sonic Wave Animation in Python Tkinter

How to Create a Sonic Wave Animation in Python Tkinter


In this Python Tutorial we will see How to Create a Sonic Wave animation that features animated bars with dynamic colors, glow effects, and smooth sine wave motion Using Python Tkinter.

What We Are Gonna Use In This Project:

- Python Programming Language.
- Tkinter (GUI).
- VS Editor.






Project Source Code:




import tkinter as tk
import math
import time
import colorsys

class SonicWave(tk.Canvas):

def __init__(self, master=None, **kwargs):
# Configuration
self.BAR_COUNT = 7
self.BAR_WIDTH = 5
self.BAR_GAP = 10
self.BAR_HEIGHT = 65
self.ANIMATION_DELAY = 1500 # milliseconds for full cycle

# Dark background color
bg_color = "#111122"

# Set canvas dimensions
width = self.BAR_COUNT * (self.BAR_WIDTH + self.BAR_GAP) + 40
height = self.BAR_HEIGHT + 60

# Initialize the canvas with our background color
super().__init__(master, width=width, height=height, bg=bg_color,
highlightthickness=0, **kwargs)

# Define colors
self.colors = [
"#00eeff", # blue
"#b300ff", # purple
"#ff00ff", # pink
"#0aff0a", # green
"#ff3300" # orange
]

# Initialize bar heights and animation state
self.bar_heights = [0.2] * self.BAR_COUNT
self.hue_shift = 0.0

# Start the animation
self.is_running = True
self.animate()


def get_color_with_shift(self, base_color, offset=0):
"""Apply a hue shift to a color for dynamic color effects"""
# Convert hex to RGB
r = int(base_color[1:3], 16) / 255.0
g = int(base_color[3:5], 16) / 255.0
b = int(base_color[5:7], 16) / 255.0

# Convert RGB to HSV
h, s, v = colorsys.rgb_to_hsv(r, g, b)
# Apply the hue shift
h = (h + self.hue_shift + offset) % 1.0
# Convert back to RGB
r, g, b = colorsys.hsv_to_rgb(h, s, v)

# Convert to hex
return f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"

def animate(self):
"""Main animation loop"""
if not self.is_running:
return

self.update_bar_heights()
self.draw_spinner()

# Schedule the next animation frame
self.after(30, self.animate)


def update_bar_heights(self):
"""Update the heights of each bar based on a sine wave function"""
current_time = time.time() * 1000 # Convert to milliseconds

# Update each bar's height based on sine wave function
for i in range(self.BAR_COUNT):
# Calculate phase offset for each bar
phase_offset = i * (math.pi / 8)

# Use sine wave to animate heights (0.2 to 1.0 range)
progress = (current_time % self.ANIMATION_DELAY) / self.ANIMATION_DELAY
angle = 2 * math.pi * progress + phase_offset
self.bar_heights[i] = 0.2 + 0.8 * abs(math.sin(angle))

# Gradually shift the hue
self.hue_shift = (self.hue_shift + 0.005) % 1.0




def create_text_shadow(self, x, y, text, font_config):
# Create shadow text (slight offset, darker color)
shadow_color = "#555555"
self.create_text(x+2, y+2, text=text, fill=shadow_color, font=font_config)

# Create main text with a fixed color
main_color = "#FFFFFF" # Use white color
self.create_text(x, y, text=text, fill=main_color, font=font_config)



def draw_spinner(self):
"""Draw the spinner with visual elements"""
# Clear the canvas
self.delete("all")

# Calculate layout dimensions
total_width = self.BAR_COUNT * (self.BAR_WIDTH + self.BAR_GAP) - self.BAR_GAP
start_x = (self.winfo_width() - total_width) // 2
base_y = (self.winfo_height() + self.BAR_HEIGHT) // 2 - 10

# Draw "SONIC WAVE" text label
# Ensure the text is positioned in a visible area
text_y = min(base_y + self.BAR_HEIGHT // 2 + 20, self.winfo_height() - 20)
self.create_text_shadow(
self.winfo_width() // 2,
text_y,
"SONIC WAVE",
("Arial", 13, "bold")
)

# Draw bars
for i in range(self.BAR_COUNT):
x = start_x + i * (self.BAR_WIDTH + self.BAR_GAP)
height = int(self.bar_heights[i] * self.BAR_HEIGHT)
y = base_y - height

# Get color based on current animation state with dynamic hue shifting
bar_color = self.get_color_with_shift(self.colors[i % len(self.colors)],
i * 0.05)

# Draw the bar
self.create_rectangle(
x, y, x + self.BAR_WIDTH, base_y,
fill=bar_color, outline="", width=0
)
# Create a glow effect by drawing multiple rectangles
for j in range(1, 5):
# Create outlines for glow effect
self.create_rectangle(
x - j, y - j, x + self.BAR_WIDTH + j, base_y + j,
outline=bar_color, width=1
)

def stop_animation(self):
"""Method to stop the animation when no longer needed"""
self.is_running = False



class AppFrame(tk.Frame):
"""A frame to hold the spinner with UI elements"""

def __init__(self, master=None, **kwargs):
super().__init__(master, **kwargs)
self.config(bg="#0d0d18", padx=25, pady=25)
self.pack(fill=tk.BOTH, expand=True)

# Create a background
self.create_background()

# Add the spinner
self.spinner = SonicWave(self)
self.spinner.pack(pady=10)

# Add a version or title or any text label
version_label = tk.Label(
self,
text="v2.0",
bg="#0d0d18",
fg="#444444",
font=("Arial", 8)
)
version_label.pack(side=tk.BOTTOM, anchor=tk.SE, padx=5, pady=5)

def create_background(self):
"""Create a background frame"""
gradient_frame = tk.Frame(self, width=300, height=250, bg="#0d0d18")
gradient_frame.place(x=0, y=0, relwidth=1, relheight=1)





def main():
root = tk.Tk()
root.title("Sonic Wave")

# Set dark theme for the window
root.configure(bg="#0a0a14")

# Create our app frame
app_frame = AppFrame(root)

# Set window size and position
root.geometry("300x250")
root.eval('tk::PlaceWindow . center') # Center the window

# Make the window non-resizable for consistent layout
root.resizable(False, False)

# Handle window close event
def on_closing():
app_frame.spinner.stop_animation()
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)

# Start the main event loop
root.mainloop()


if __name__ == "__main__":
main()



The Final Result:

Python Tkinter Sonic Wave Animation 1

Python Tkinter Sonic Wave Animation 2

Python Tkinter Sonic Wave Animation 3









Free Python Projects Source Code

Download Free Python Projects Source Code

Free Python Projects Source Code



here's a list of free python projects source code + video tutorial.

this list contains python games, mini apps, form designs.

if you want to get premium python projects source code click HERE .


 1 - Python Quiz App Project Source Code 


How to Make a Simple Quiz App Using Python And Tkinter.


 2 - Python Calculator Project Source Code 


How To Make A Calculator With Swith  To Do The Basic Operations (+, -, /, *) Using Python Tkinter.


 3 - Python Rock Paper Scissors Game Source Code 


How to Make a Simple Rock, Paper, Scissors Game Using Python Tkinter.


 4 - Python Login & Register Form With MySQL DataBase Source Code 


How To Make a Design a Login Form And a Register Form In Python Tkinter, And How To Connect Those Two Form With MySQL Database.


 5 - Python Drawing App Source Code 


How to Make Drawing Application Using Python And the Tkinter library.


 6 - Python Expenses And Incomes Tracker Project Source Code 


How To Create A Simple Expenses and Incomes Tracker Application Using Python And Tkinter.


 7 - Python Guess The Word Game Source Code 


How to Make a Simple Word Guessing Game App In Python Tkinter.


 8 - Python Dashboard Form Design Source Code 


How To Design A Dashboard Form In Python Tkinter.


 9 - Python Image Editor Project Source Code 


How To Ceate A Simple Photo Editor Application Using Tkinter And The Pillow Library.





▶ Download Premium Python Project Source Code




Create 3D Text Animations In Python Tkinter

How To Create an Animated Text in Python Using Tkinter

How to Create 3D Text Animation In Python Tkinter


In this Python Tutorial we will see How to Create an animated text effects using Python and Tkinter library.
The text appears with a growth animation, cycles through vibrant colors, and maintains subtle movement patterns while displaying layered shadow effects for depth and impact.

What We Are Gonna Use In This Project:

- Python Programming Language.
- Tkinter (GUI).
- VS Editor.






Project Source Code:




import tkinter as tk
import math
import time
from tkinter import font

class TextAnimation(tk.Canvas):
"""
A smooth animated text effect that creates a glowing, colorful text
with shadow layers and gentle rotation.
"""
def __init__(self, master, text, **kwargs):
super().__init__(master, **kwargs)
self.text = text
# Animation state variables
self.scale = 0.1 # Text starts small and grows
self.is_growing = True # Flag to control growth phase
self.rotation_angle = 0 # Current rotation angle
self.color_time = 0 # Time variable for color cycling
# Animation settings
self.grow_speed = 0.02 # How fast text grows (0.01 = slow, 0.05 = fast)
self.rotation_speed = 0.1 # How fast text rotates
self.color_speed = 0.03 # How fast colors change
self.shadow_layers = 30 # Number of shadow/glow layers
# Colors for the gradient effect (RGB values)
self.colors = [
(255, 0, 128), # Hot pink
(255, 102, 0), # Orange
(255, 215, 0), # Gold
(0, 255, 255) # Cyan
]
# List of texts to cycle through when clicked
self.text_options = [
"FIGHT!",
"POWER!",
"EPIC!",
"AWESOME!",
"VICTORY!",
"LEGEND!",
"SUPREME!",
"ULTIMATE!"
]
self.current_text_index = 0
# Set up click event to change text
self.bind("<Button-1>", self.on_click)
# Start the animation loop
self.animate()

def animate(self):
"""
Main animation loop - called repeatedly to update the animation
"""
# Update animation values
self.update_animation_values()
# Clear the canvas and redraw everything
self.delete("all")
self.draw_animated_text()
# Schedule the next frame (20ms delay)
self.after(20, self.animate)
def update_animation_values(self):
"""
Update all the animation variables for smooth movement
"""
# Handle the growing phase when text first appears
if self.is_growing:
self.scale += self.grow_speed
if self.scale >= 1.0:
self.scale = 1.0
self.is_growing = False
# Update rotation and color cycling (always happening)
self.rotation_angle += self.rotation_speed
self.color_time += self.color_speed

def draw_animated_text(self):
"""
Draw the text with all effects: shadows, colors, and rotation
"""
# Get canvas dimensions for centering
width = self.winfo_width()
height = self.winfo_height()
center_x = width // 2
center_y = height // 2
# Calculate font size based on window size and current scale
base_font_size = min(width, height) // 6
current_font_size = int(base_font_size * self.scale)
text_font = font.Font(family="Impact", size=current_font_size, weight="bold")
# Draw shadow layers first (back to front)
self.draw_shadow_layers(center_x, center_y, text_font)
# Draw the main text on top
self.draw_main_text(center_x, center_y, text_font)


def draw_shadow_layers(self, x, y, text_font):
"""
Draw multiple shadow layers
"""
for layer in range(self.shadow_layers, 0, -1):
# Calculate how far back this shadow layer is (0.0 to 1.0)
depth = layer / self.shadow_layers
# Get color for this shadow layer
shadow_color = self.get_gradient_color(depth + self.color_time)
# Make shadow
color_hex = self.rgb_to_hex(shadow_color)
# Calculate shadow offset with gentle wave motion
wave = math.sin(self.rotation_angle + layer * 0.1)
offset_x = layer * 2 + wave * 1.5
offset_y = layer * 2 + wave * 1.5
# Draw this shadow layer
self.create_text(
x + offset_x, y + offset_y,
text=self.text,
font=text_font,
fill=color_hex,
anchor="center"
)


def draw_main_text(self, x, y, text_font):
"""
Draw the main text with bright colors and subtle rotation
"""
# Get the main color
main_color = self.get_gradient_color(self.color_time)
color_hex = self.rgb_to_hex(main_color)
# Add gentle swaying motion (only after growing is complete)
sway = 0
if not self.is_growing:
sway = math.sin(self.rotation_angle * 0.5) * 3
# Draw the main text
self.create_text(
x + sway, y,
text=self.text,
font=text_font,
fill=color_hex,
anchor="center"
)
# Add a bright highlight on top
highlight_color = self.rgb_to_hex((255, 255, 255))
self.create_text(
x + sway - 1, y - 1,
text=self.text,
font=text_font,
fill=highlight_color,
anchor="center"
)


def get_gradient_color(self, position):
"""
Get a color from the gradient based on position (0.0 to 1.0)
Creates smooth color transitions between the defined colors
"""
# Keep position between 0 and 1
position = position % 1.0
# Find which two colors to blend
color_sections = len(self.colors) - 1
scaled_position = position * color_sections
color_index = int(scaled_position)
blend_amount = scaled_position - color_index
# Get the two colors to blend
color1 = self.colors[color_index]
color2 = self.colors[(color_index + 1) % len(self.colors)]
# Blend the colors smoothly
r = int(color1[0] + (color2[0] - color1[0]) * blend_amount)
g = int(color1[1] + (color2[1] - color1[1]) * blend_amount)
b = int(color1[2] + (color2[2] - color1[2]) * blend_amount)
return (r, g, b)


def on_click(self, event):
"""
Handle mouse clicks to change the text
"""
# Move to the next text in the list
self.current_text_index = (self.current_text_index + 1) % len(self.text_options)
self.text = self.text_options[self.current_text_index]
# Reset the growing animation
self.scale = 0.3 # Start a bit bigger for text changes
self.is_growing = True
# Add a little color boost when text changes
self.color_time += 0.5


def rgb_to_hex(self, rgb_color):
"""
Convert RGB color values to hex format for tkinter
rgb_color: tuple of (red, green, blue) values (0-255)
"""
r, g, b = rgb_color
return f"#{r:02x}{g:02x}{b:02x}"




class MainWindow(tk.Tk):
"""
Main application window that contains the text animation
"""
def __init__(self):
super().__init__()
# Window setup
self.title("Smooth Text Animation")
self.geometry("800x400")
self.configure(bg="#1a1a1a") # Dark background
# Create the animated text
self.animation = TextAnimation(
self,
text="FIGHT!",
bg="#1a1a1a", # Match window background
highlightthickness=0 # Remove border
)
# Make the animation fill the entire window
self.animation.pack(fill=tk.BOTH, expand=True)


# Run the application
if __name__ == "__main__":
app = MainWindow()
app.mainloop()




The Final Result:

Python Text Animation With 3D Effects Using Tkinter - 1

Python Text Animation With 3D Effects Using Tkinter - 2

Python Text Animation With 3D Effects Using Tkinter - 3

Python Text Animation With 3D Effects Using Tkinter - 4

Python Text Animation With 3D Effects Using Tkinter - 5

Python Text Animation With 3D Effects Using Tkinter - 6

Python Text Animation With 3D Effects Using Tkinter - 7

Python Text Animation With 3D Effects Using Tkinter - 8