magicgui.magicgui
#
magicgui.magicgui(function=None, *, layout='vertical', scrollable=False, labels=True, tooltips=True, call_button=None, auto_call=False, result_widget=False, main_window=False, app=None, persist=False, raise_on_unknown=False, **param_options)
#
Return a FunctionGui
for function
.
Parameters:
-
function
(
Callable
, default:None
) –The function to decorate. Optional to allow bare decorator with optional arguments. by default
None
-
layout
(
str
, default:'vertical'
) –The type of layout to use. Must be
horizontal
orvertical
by default "vertical". -
scrollable
(
bool
, default:False
) –Whether to enable scroll bars or not. If enabled, scroll bars will only appear along the layout direction, not in both directions.
-
labels
(
bool
, default:True
) –Whether labels are shown in the widget. by default True
-
tooltips
(
bool
, default:True
) –Whether tooltips are shown when hovering over widgets. by default True
-
call_button
(
bool or str
, default:None
) –If
True
, create an additional button that calls the original function when clicked. If astr
, set the button text. If None (the default), it defaults to True whenauto_call
is False, and False otherwise. -
auto_call
(
bool
, default:False
) –If
True
, changing any parameter in either the GUI or the widget attributes will call the original function with the current settings. by default False -
result_widget
(
bool
, default:False
) –Whether to display a LineEdit widget the output of the function when called, by default False
-
main_window
(
bool
, default:False
) –Whether this widget should be treated as the main app window, with menu bar, by default False.
-
app
(
Application or str
, default:None
) –A backend to use, by default
None
(use the default backend.) -
persist
(
bool
, default:False
) –If
True
, when parameter values change in the widget, they will be stored to disk and restored when the widget is loaded again withpersist = True
. Callmagicgui._util.user_cache_dir()
to get the default cache location. By default False. -
raise_on_unknown
(
bool
, default:False
) –If
True
, raise an error if magicgui cannot determine widget for function argument or return type. IfFalse
, ignore unknown types. By default False. -
param_options
(
dict[str, dict]
, default:{}
) –Any additional keyword arguments will be used as parameter-specific options. Keywords must match the name of one of the arguments in the function signature, and the value must be a dict of keyword arguments to pass to the widget constructor.
Returns:
-
result (
FunctionGui or Callable[[F], FunctionGui]
) –If
function
is notNone
(such as when this is used as a bare decorator), returns a FunctionGui instance, which is a list-like container of autogenerated widgets corresponding to each parameter in the function. Iffunction
isNone
such as when arguments are provided likemagicgui(auto_call=True)
, then returns a function that can be used as a decorator.
Examples:
>>> @magicgui
... def my_function(a: int = 1, b: str = 'hello'):
... pass
...
>>> my_function.show()
>>> my_function.a.value == 1 # True
>>> my_function.b.value = 'world'