Skip to content

Adding uninteractive labels to @magicgui functions #567

Open
@multimeric

Description

@multimeric

❓ Questions and Help

Let's say I have a simple function that I want made into a GUI, but I want to display some text to the user as a label that isn't treated as a user input. For example it might be instructions to the user. I'm not sure how to do this with magicgui. It doesn't seem to use the docstring, nor is there any argument to @magicgui that helps here. I could created a Label widget as a string argument that is immutable, but that gives me a confusing function signature.

With this example, how could I add the label "Here is some descriptive text I want to show my users" to the top of the form?

from typing import Annotated, Literal
from magicgui import magicgui

@magicgui
def my_function(
    param_a: int,
    param_b: Annotated[int, {'widget_type': "Slider", 'max': 100}] = 42,
    param_c: Literal["First", "Second", "Third"] = "Second"
):
    """Here is some descriptive text I want to show my users"""
    print("param_a:", param_a)
    print("param_b:", param_b)
    print("param_c:", param_c)

my_function.show(run=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions