""" ChapterAnimation/bubbleKey.py bounce: move a circle left - right win.checkKey() is false (none) and is not waiting for the key to be pressed """ from graphics import * winW,winH = 400,300 # window Width x Height from math import * #for sqrt def main(): win = GraphWin( "Bubble", winW, winH ) radius = 30 myc = Circle( Point(10,70), radius) myc.setFill( '#ffff00' ) myc.draw( win ) speed = 3 while True: myc.move(speed, 0 ) time.sleep(0.01) pc = myc.getCenter() if ( pc.getX()+radius > winW or pc.getX() < 0 ): speed = speed * -1 k = win.checkKey() if k == 'Up' : myc.setFill("red") speed = 0 #stop the movement elif (k == 'Down'): #continue speed = 3 main()