Skip to content
Advertisement

Python ipywidgets – empty widget that can be filled inside a function

Let’s say I have a dropdown widget with some numbers and a floatext widget with some other numbers. I would like to define a widget that takes an empty parameter and can be dynamically filled with the calculation made inside the function which in this case would be mW.

I could do it by not defining the mW widget and returning this inside the function but I was hoping for another way.

JavaScript

My expected outcome would be the below with 400 or another number calculated dynamically filled in the M box.

enter image description here

Advertisement

Answer

For:

“Defining a widget that takes an empty parameter and can be dynamically filled with the calculation made inside the function”

You can simply use a FloatText widget with no parameters, and then setting the value inside the function; as follows:

JavaScript

Then, for dinamically checking the value of mW, you can use the threading library:

JavaScript

For any doubt:

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