Buttons, radio buttons, sliders, menus

315 views
Skip to first unread message

Bruce Sherwood

unread,
Jul 26, 2016, 8:45:30 PM7/26/16
to Glowscript Users
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.


Bruce Sherwood

unread,
Jul 26, 2016, 10:45:35 PM7/26/16
to Glowscript Users
For a radio button, the key attribute is "checked" -- True if checked, False if not.

Bruce Sherwood

unread,
Jul 27, 2016, 12:18:20 AM7/27/16
to Glowscript Users
There is now detailed documentation on button, radio, slider, and menu:

Bruce Sherwood

unread,
Jul 27, 2016, 6:20:12 PM7/27/16
to Glowscript Users
I made a mistake in a detail of the menu object, where the attribute for reading and writing which choice has been selected should be "selected", not "select". Now fixed in 2.1 and in the documentation.
Reply all
Reply to author
Forward
0 new messages