Note
Click here to download the full example code
Quantities with pint#
Pint is a Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units. https://pint.readthedocs.io/en/stable/
Out:
<FunctionGui widget(q=<Quantity(1, 'millisecond')>)>
try:
from pint import Quantity
except ImportError:
msg = (
"This example requires the pint package. "
"To use magicgui with pint please `pip install pint`, "
"or use the pint extra: `pip install magicgui[pint]`"
)
raise ImportError(msg) from None
from magicgui import magicgui
@magicgui
def widget(q=Quantity("1 ms")):
"""Widget allowing users to input quantity measurements."""
print(q)
widget.show(run=True)
Total running time of the script: ( 0 minutes 0.165 seconds)
Download Python source code: pint_quantity.py