I need help... why is the ball...
So this is the code:
from tkinter import * import random import time tk = Tk() # create toolkit object WIDTH=500 HEIGHT=500 canvas = Canvas(tk, width=WIDTH, height=HEIGHT) tk.title("2 Ball") canvas.pack() ball = canvas.create_oval(5,5, 30, 30, fill="blue") xs = 1 ys= 2 ball2=canvas.create_oval(5,5,30,30, fill="red") x=2 y=1 while True: canvas.move(ball, xs, ys) canvas.move(ball2, x, y) pos = canvas.coords(ball) pos2 = canvas.coords(ball2) if pos<0 or pos>WIDTH: xs=-xs if pos<0 or pos>HEIGHT: ys=-ys canvas.update() time.sleep(0.01) tk.mainloop()
The red ball went out of the window...
So how do I fix this?
Btw this is python
Answered by TheBest156 [earned 5 cycles]