Skip to content

Note

Click here to download the full example code

Callable functions demo#

This example demonstrates handling callable functions with magicgui.

callable

Out:

<FunctionGui example(func='f')>


from magicgui import magicgui


def f(x: int, y="a string") -> str:
    """Example function F."""
    return f"{y} {x}"


def g(x: int = 6, y="another string") -> str:
    """Example function G."""
    return f"{y} asdfsdf {x}"


@magicgui(call_button=True, func={"choices": ["f", "g"]})
def example(func="f"):
    """Ëxample function."""
    pass


def update(f: str):
    """Update function."""
    if len(example) > 2:
        del example[1]
    example.insert(1, magicgui(globals()[f]))


example.func.changed.connect(update)
example.show(run=True)

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

Download Python source code: callable.py

Download Jupyter notebook: callable.ipynb

Gallery generated by mkdocs-gallery