winput: numeric and string input

290 views
Skip to first unread message

Bruce Sherwood

unread,
Nov 7, 2018, 12:04:18 PM11/7/18
to Glowscript Users
Now available in GlowScript VPython (but not yet in VPython 7) is the winput object (widget input) which lets the user type a numeric expression or string input. The documentation is at


Here is an extract from that widget documentation page:

---------------------------------------------------------------------------------
Here is the basic idea for using winput:

def T(s): 
    print(s.text, s.number)
winput( bind=T )


The winput object (widget input) displays a box in which the user can input a numeric expression or text. The user must select the text either by clicking in the box or by using the tab key. 


bind The name of the function to be called when the user presses Enter. 


type "numeric" (the default) or "string". If it is numeric, the user can input expressions such as 3+2*sqrt(5.2e4). An error message is displayed if there is something wrong with the expression, and the bound function is not called. 


width The width of the winput box in pixels; default is 100. 


height The height of the winput box in pixels; default is 20. 


text The text displayed in the box, whether entered by the user or set by the program (for example, one might wish to set the text to be displayed before the user enters anything, which the user can modify). 


number The number that results from evaluating the user's input text if the type is "numeric" (otherwise it is None). If a numeric winput object is named W and the user enters 3+5, then W.text will be the string "3+5" and W.number will be 8. 


disabled If True, the text is grayed out and the winput is inactive. 


delete() If W is a winput, W.delete() deletes the winput box from the display.


Bruce


Bruce Sherwood

unread,
Nov 7, 2018, 4:07:14 PM11/7/18
to Glowscript Users
I forgot to add this attribute of winput, which is shared with other widgets (the documentation has been updated):

pos Position to which to append the widget (see "Appending to anchor points" below). Cannot be changed after creating the object.

Bruce
Reply all
Reply to author
Forward
0 new messages