Skip to content
Advertisement

How could I use and manipulate float numbers in PyPanel using textbox widgets instead of sliders?

The Problem: I’m trying to get a float number user input indicator box like this which I designed on LabView in Python using PyPanel to eventually make a dashboard with multiple similar boxes (etc.).

Background: I’m trying to make a user friendly dashboard using PyPanel. I am new to dashboards but have some experience in running calculations and modelling in Python using Jupyter Notebook.

PyPanel only strictly allows float numbers to be inputted by a user into a slider as per this picture with code provided below:

JavaScript

PyPanel also allows a textbox for strings but not numbers as seen in the code below:

JavaScript

Which can then be called on using display(x.value) but the output is in a string (i.e. ‘51.85’) which means I cannot do operations with it. When I try;

  • multiplying (i.e. display(x.value*2)) I get '51.8551.85'.

  • adding (i.e display(x.value+2)) I get the error:

JavaScript

The Question: How can I get a similar user-input widget to this number textbox that I’ve originally used (mentioned in the opening “Problem” statement) using PyPanel to accept user-inputted floating numbers (e.g. 51.85)? Does it involve some manipulation of PyPanel’s textbox widget and, if so, what can be done to make basic operations possible from user-inputted numbers?

Advertisement

Answer

Save yourself a headache and just use the string input and convert str to float with float()

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement