Skip to content
← Back to Community
I need help... why is the ball...
Profile icon
P0GCHAMPB0i

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]<0 or pos[2]>WIDTH: xs=-xs if pos[1]<0 or pos[3]>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]
View Answer
Voters
Profile icon
bot111222
Profile icon
P0GCHAMPB0i
Comments
hotnewtop
Profile icon
TheBest156

Fix it in tinkercad, then print it out. Btw how r u using tinkercad in repl python?

Profile icon
P0GCHAMPB0i
Profile icon
P0GCHAMPB0i

@TheBest156 this is python with tkinter