Need to have balls moved when touched using getmouse() also need an if then statement when ball is clicked to have it moved

Recommended Answers

All 5 Replies

heres the code
from graphics import *
import time

def main():

    win = GraphWin('Dribbling', 400, 450)
    from graphics import *

import time

def main():
    win = GraphWin('Dribbling', 400, 450)
    win.setBackground ("white")

    cir1 =Point( win.getmouse(), 40).draw(win)


    cir1 = Circle(Point(40,100), 25)
    cir1.setFill("blue")
    cir1.draw(win)

    cir2 = Circle(Point(150,125), 25)
    cir2.setFill("yellow")
    cir2.draw(win)

    for i in range(50):
        cir1.move(0, 5)
        time.sleep(.05)

    for i in range(50):
        cir1.move(0, -5)
        time.sleep(.05)

    for i in range(50):
        cir2.move(0,5)
        time.sleep(.05)

    for i in range(50):
        cir2.move(0,-5)
        time.sleep(.05)

main()



win.setBackground ("white")

cir1 =Point( win.getmouse(), 40).draw(win)


cir1 = Circle(Point(40,100), 25)
cir1.setFill("blue")
cir1.draw(win)

cir2 = Circle(Point(150,125), 25)
cir2.setFill("yellow")
cir2.draw(win)

for i in range(50):
    cir1.move(0, 5)
    time.sleep(.05)

for i in range(50):
    cir1.move(0, -5)
    time.sleep(.05)

for i in range(50):
    cir2.move(0,5)
    time.sleep(.05)

for i in range(50):
    cir2.move(0,-5)
    time.sleep(.05)

main()

What happens when you try to run it?

(BTW, there seems to have been some kind of problem when you pasted the code, but don't worry, it isn't hard to see to tell what the code actually is. These things happen.)

Oh, I forgot to add that the graphics module you are using is not part of the Python standard library; I have a pretty good guess as to which one you are using, but I'm not certain. Do you know which it is?

That was the one I was thinking it might be, but I was hoping the OP could confirm this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.