Doing math directly in UI Widgets

To whomever can suggest a solution for my ignorance…

I want to create a UI input field that allows for integers, but I also want my end user to be able to do basic math in the field as well. So they could type “300+400” “enter” and the result is “700.”

The Widget UI elements do not appear to allow me to do this… any thoughts? Or is this something I custom build for my purposes?


Widgets won’t do this out of the box, no. I think you could build it with a field widget (numeric ones won’t take text) and then react to value changes by doing a Python eval on the results. Or, if you don’t want full Python code evaluation, just math, use the literal_eval function in the builtin Python ast library.

Thanks for clarifying Ivan!