from visual.controls import *
from visual import rate
def swapColor(): # click the button to change its color
if butt.button.color == color.red: butt.button.color = color.cyan
else: butt.button.color = color.red
display()
controls()
butt = button(text='button', color=color.red, action=lambda:swapColor())
while True: rate(100)
# This always works in my Windows 7 computer, which has
# python 2.7.6 (this is 32 bit, windows X86 msi installer)
# and VPython-Win-Py2.7-5.74
# However, on a Mac OSX 10.7.5, it is intermittent:
# Sometimes the color does not change.
# This Mac has "python 2.7.9 for mac 0sx 10.6 and higher"
# and then vpython-mac-py2.7-6.11, then ActiveTcl.
# (To make vpython work with py2app, I've eliminated tga stuff.)
# On the Mac, to make it misbehave EVERY time, go to Mac Preferences,
# Mouse, and set the double-click speed as slow as possible.
# You will see that the first click changes the button color, but
# if the mouse is not moved and you click a second time the color
# is not changed. But move the mouse off the button, then move it
# back onto the button, and then click---it's ok every time.