Learn Python multiple animations 🎞️

preview_player
Показать описание
Python tkinter animation animate multiple objects tutorial for beginners

#Python #tkinter #animation #animate #multiple #objects #tutorial #beginners
Рекомендации по теме
Комментарии
Автор


from tkinter import *
from Ball import *
import time

window = Tk()

WIDTH = 500
HEIGHT = 500

canvas = Canvas(window, width=WIDTH, height=HEIGHT)
canvas.pack()

volley_ball = Ball(canvas, 0, 0, 100, 1, 1, "white")
tennis_ball = Ball(canvas, 0, 0, 50, 4, 3, "yellow")
basket_ball = Ball(canvas, 0, 0, 125, 3, 5, "orange")
bowling_ball = Ball(canvas, 0, 0, 75, 2, 1, "black")

while True:
volley_ball.move()
tennis_ball.move()
basket_ball.move()
bowling_ball.move()
window.update()
time.sleep(0.01)

window.mainloop()

class Ball:


def __init__(self, canvas, x, y, diameter, xVelocity, yVelocity, color):
self.canvas = canvas
self.image = canvas.create_oval(x, y, diameter, diameter, fill=color)
self.xVelocity = xVelocity
self.yVelocity = yVelocity

def move(self):
coordinates =

or coordinates[0]<0):
self.xVelocity = -self.xVelocity
or coordinates[1]<0):
self.yVelocity = -self.yVelocity

self.canvas.move(self.image, self.xVelocity, self.yVelocity)

BroCodez
Автор

Excellent video 💯👍👏 I feel I can almost make a AAA game with all this knowledge 📚 Let's go.

davidcalebpaterson
Автор

A few comments on that programme :
- For the ball to be a Real circle, you have to enter : create_oval(x, y, x+diametre, y+diametre, fill=color)
Otherwise, some initial conditions can "ovalise" your balls (painful)
- I change the rebound condition to :
if coordonnee[2] >=self.canevas.winfo_width() and self.x_vel>0 or coordonnee[0]<0 and self.x_vel<0:

Otherwise my balls tend to get stuck against the wall (also painful)

- the last mainloop() stuff is useless as the program will never go after the while True loop

Good video none the less. Thanks

nicolaspoyet
Автор

The person who put a dislike wasn’t able to get the code running.

xl_lol
Автор

Mr Bro you're extremely awesome
Dude that was perfectly perfect 👌

The-Martian
Автор

Thanks, Bro! I was too lazy to write code for each new ball, so I tweaked the code :) With some random generations, this code can be turned into a generator of the desired (or random) number of balls with random size, speeds and colour without the need to manually create each ball:

def gen_speed(): return random.randint(0, 10)
def gen_size(): return random.randint(10, 299)
def gen_coords(): return random.randint(300, 699)
def gen_color(): return ('#%06X' % random.randint(0,

And this is the code to generate these balls in the list 'balls':

for i in range(int(number)):
i = Ball(canvas, gen_coords(), gen_coords(), gen_size(), gen_speed(), gen_speed(), gen_color()) # Everything is generated automatically
balls.append(i)
return balls

And the returned list of 'Ball' objects is used in while True loop

Pelmen
Автор

Thank a lot for your precious time, my bro...You one of a kind bro...!

hilaryeins
Автор

This solution almost solved my problem. I am trying to make spectrogram. From bottom to top should be vertical line, color coded according to fft result. This line should start at the right edge, then as new data (sound) incoming, slowly moves to the left. I am unable to understand how to move once drawn line. But at least now, I can move whole object consisting of hundreds of lines. Wrong way, but I have no knowledge how to move canvas to the left as new vertical lines appearing. Tkinter documentation is way too confusing.

MilanKarakas
Автор

I'm new to python animation, thanks, Do python Tkinter have a random() function?

worldofstrings
Автор

Where is the full C# video? also do you recommend C# before C++?

x-
Автор

Can this be used as buttons and play audio when clicked as they stay moving like a floating playlist?

livenlearn
Автор

Cool. Thanks for the tutorial. This inspire me to create a channel myself. Could you share the setup, steps, software, etc. to start?

mikebui
Автор

Him: They will bounce off the border into another direction
Me: Like the samsung logo!

ImMillerMansSis
Автор

That was easy to understand and to rebuild. Great video! But the moving circles do not look very smooth. They look like they are getting cut. Do you have a solution for this?

maxbecker
Автор

step 3 = done
step 1 = done 👍
step 2 = done 🗯
Another great video, helps a lot! Thanks Bro!

derpfisti
Автор

I love ur video, rlly ejoyed.
And i want to ask how can i make ball move randomly?

marekhomiak
Автор

if we want to save it a s a video then what to do?

KasimKhan-lksw
Автор

I struggled with this a bit, in visual studio code, I had to save to Ball.py before it would work. But once I did I had no further probs. Thanks bro!

jhassee
Автор

How can I move images other than Animated balls?

HunaBopa
Автор

Nice vids, please make tutorial how to animate object using python Manim like 3b1b ?

ibanguniverse