Skip to content

Note

Click here to download the full example code

Optional user choice#

Optional user input using a dropdown selection widget.

optional

Out:

<FunctionGui f(path: str = None)>


from typing import Optional

from magicgui import magicgui


# Using optional will add a '----' to the combobox, which returns "None"
@magicgui(path={"choices": ["a", "b"]})
def f(path: Optional[str] = None):
    """Öptional user input function."""
    print(path, type(path))


f.show(run=True)

Total running time of the script: ( 0 minutes 0.039 seconds)

Download Python source code: optional.py

Download Jupyter notebook: optional.ipynb

Gallery generated by mkdocs-gallery