Link

Link control

A clickable element that opens a URL in the system's default web browser when tapped. Links can display a simple text title or custom content views. The URL can use any scheme supported by the system, including https://, mailto:, and tel:.

Constructor

nib.Link(
    title=None,
    url="",
    content=None,
    **modifiers,
)

Parameters

Parameter Type Default Description
title str None Text to display as the link. For custom content, use the content parameter instead.
url str "" The URL to open when the link is tapped. Supports http://, https://, mailto:, tel:, and other system URL schemes.
content View None Custom view to display as the link content. Alternative to title.
**modifiers Common view modifiers: foreground_color, font, padding, opacity, etc.

Examples

link_simple_text_link

import nib


def main(app: nib.App):
    app.title = "Help"
    app.icon = nib.SFSymbol("questionmark.circle")

    app.build(
        nib.VStack(
            controls=[
                nib.Text("Need a hand?", font=nib.Font.HEADLINE),
                nib.Link(
                    "Read the documentation", url="https://edo.codeberg.page/nib/"
                ),
                nib.Link("Report a problem", url="https://codeberg.org/edo/nib/issues"),
                nib.Link(
                    "Email support",
                    url="mailto:support@example.com",
                    foreground_color=nib.Color.SECONDARY,
                ),
            ],
            spacing=10,
            padding=20,
            alignment=nib.Alignment.LEADING,
        )
    )


nib.run(main)

link_link_custom_content

import nib


def main(app: nib.App):
    app.title = "Project"
    app.icon = nib.SFSymbol("shippingbox")
    app.height = 220

    def link(icon, text, url):
        return nib.Link(
            url=url,
            content=nib.HStack(
                controls=[nib.SFSymbol(icon), nib.Text(text)],
                spacing=6,
            ),
        )

    app.build(
        nib.VStack(
            controls=[
                nib.Text("nib", font=nib.Font.HEADLINE),
                nib.Text(
                    "Native macOS menu bar apps in Python",
                    foreground_color=nib.Color.SECONDARY,
                ),
                nib.Divider(),
                link("globe", "Website", "https://edo.codeberg.page/nib/"),
                link(
                    "chevron.left.forwardslash.chevron.right",
                    "Source",
                    "https://codeberg.org/edo/nib",
                ),
                link("shippingbox", "PyPI", "https://pypi.org/project/pynib/"),
            ],
            spacing=10,
            padding=20,
            alignment=nib.Alignment.LEADING,
        )
    )


nib.run(main)