Closing a window onclick - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Closing a window onclick

XeonicXpressioXeonicXpressio Posts: 5Member
I have a program that I want to keep looping uptil the user clicks in the window. It is a ball bouncing around in a window using the graphics module. I tried using win.getmouse() and then win.close(), but then it has to wait between every loop and will only go once.
[code]
def circdrawer(x,y,xdir,ydir,color,n,win):
for i in range(0,700):
xdir,ydir = slope(x,y,xdir,ydir)
color,n = shader(x,y,color,n)
x = x + xdir
y = y + ydir
circ = Circle(Point(x,y), 4)
circ.setFill(color)
circ.draw(win)
time.sleep(.01)
circ.undraw()
[/code]
I've searched the python documentation, but don't see anything that will do this. I was thinking of something like onclick, but I can't find anything like that.

Comments

  • DrostDrost Posts: 24Member
    : I have a program that I want to keep looping uptil the user clicks in the window. It is a ball bouncing around in a window using the graphics module. I tried using win.getmouse() and then win.close(), but then it has to wait between every loop and will only go once.

    : I've searched the python documentation, but don't see anything that will do this. I was thinking of something like onclick, but I can't find anything like that.
    :

    Which (Python wrapped) GUI are you working with?
    IIRC all GUI systems that are usable by Python (of which I've heard) use the event-driven approach (well, except EasyGUI), so the program will generally be in a waiting-for-user-action loop and if something occurs it relies on the appropriate event-handler (which even might be an onclick like event).

    Drost
Sign In or Register to comment.