Multiple moving objects using python!!!

preview_player
Показать описание
#shorts #programming #tkintertutorial #tkinter Multiple moving objects how I told you!! Subscribe to don't miss a game of tic-tac-toe using python!!!
Рекомендации по теме
Комментарии
Автор

The code:

Main project code:
from tkinter import *
from Ball import *
import time
window = Tk()

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

volley_ball = Ball(canvas, 0, 0, 100, 8, 4, "white")
tennis_ball = Ball(canvas, 0, 0, 50, 7, 5, "lime")
basket_ball = Ball(canvas, 0, 0, 125, 6, 5, "orange")
bowling_ball = Ball(canvas, 0, 0, 70, 3, 2, "black")

volley_ball1 = Ball(canvas, 0, 0, 100, 2, 4, "purple")
tennis_ball1 = Ball(canvas, 0, 0, 200, 2, 9, "orange")
basket_ball1 = Ball(canvas, 0, 0, 30, 8, 9, "cyan")
bowling_ball1 = Ball(canvas, 0, 0, 90, 5, 10, "blue")

volley_ball11 = Ball(canvas, 0, 0, 221, 5, 4, "pink")
tennis_ball11 = Ball(canvas, 0, 0, 170, 2, 6, "red")
basket_ball11 = Ball(canvas, 0, 0, 140, 4, 2, "yellow")
bowling_ball11 = Ball(canvas, 0, 0, 120, 4, 9, "green")

while True:
volley_ball.move()
tennis_ball.move()
basket_ball.move()
bowling_ball.move()
volley_ball1.move()
tennis_ball1.move()
basket_ball1.move()
bowling_ball1.move()
volley_ball11.move()
tennis_ball11.move()
basket_ball11.move()
bowling_ball11.move()
window.update()
time.sleep(0.01)


window.mainloop()

Ball project code:


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 =
print(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)

Boolcoder