📘 Tutorial: How to Create a Custom Loading Animation in Python Kivy
Want to give your Kivy app a sleek, professional feel? A custom loading animation can be a perfect touch! In this tutorial, I’ll walk you through creating a simple and stylish loading animation using Python and Kivy.
🚀 What You’ll Learn:
-
How to use Kivy's
Animation
class -
Creating shapes and motion using
Canvas
-
Making reusable and customizable loading widgets
🧰 Requirements:
Make sure you have Python and Kivy installed.
pip install kivy , numpy , math
Python Kivy Loading Animation Code
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.graphics import Rectangle,Line,Ellipse,Color,RoundedRectangle
import math
from kivy.animation import Animation
class sample(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.count = 0
with self.canvas :
Color(1,1,1)
self.line = Line(rounded_rectangle = (300,300,50,20,20),width = 2)
Clock.schedule_interval(self.update,1/30)
def update(self,dt):
x = math.sin(self.count)*60
y = math.cos(self.count)*60
self.line.rounded_rectangle = (300+x,300,50-y,20,20)
self.count += 0.1
class myapp(App):
def build(self):
return sample()
if __name__ == "__main__":
myapp().run()
No comments:
Post a Comment