Now available in GlowScript 2.1 are easy to use "widgets": button, radio, slider, and (dropdown) menu.
These new objects are not yet documented in the GlowScript Help, but two of the standard example programs have been updated to use these objects:
Here is the basic idea:
box()
def B(b):
print("You clicked the button that said this: ", b.text)
button( text='Click me!', bind=B )
scene.append_to_caption('\n\n') # to place the slider under the button
def S(s):
print(s.value)
slider(bind=S)
scene.append_to_caption('\n\n') # to place the menu under the slider
def M(m):
print(m.select)
menu(choices=['cat', 'dog', 'horse'], bind=M)
When the user clicks the button, the "bound" function B is called with a pointer to the button object, so that b.text is 'Click me!'.
When the user drags the slider, the function S is called, and s.value is the value of the slider (whose default min is 0 and max is 1).
For a dropdown menu, you provide a list of choices.
The radio object (a radio button) is basically the same as a button, but there is no text.
By default a widget is appended to scene.caption_anchor, but you can specify pos=scene.title_anchor (or in some other canvas).
It is intended to make these objects available in Jupyter VPython, so that programs that use widgets can be the same in both GlowScript VPython and Jupyter VPython.