[go: up one dir, main page]

Skip to content

Link

Added in version 0.84.0

A widget to display a piece of text that opens a URL when clicked, like a web browser link.

  • Focusable
  • Container

Example

A trivial app with a link. Clicking the link open's a web-browser—as you might expect!

LabelApp Go to textualize.io

from textual.app import App, ComposeResult
from textual.widgets import Link


class LabelApp(App):
    AUTO_FOCUS = None
    CSS = """
    Screen {
        align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
        yield Link(
            "Go to textualize.io",
            url="https://textualize.io",
            tooltip="Click me",
        )


if __name__ == "__main__":
    app = LabelApp()
    app.run()

Reactive Attributes

Name Type Default Description
text str "" The text of the link.
url str "" The URL to open when the link is clicked.

Messages

This widget sends no messages.

Bindings

The Link widget defines the following bindings:

Key(s) Description
enter Open the link in the browser.

Component classes

This widget contains no component classes.


Bases: Static

A simple, clickable link that opens a URL.

Parameters:

Name Type Description Default

text

str

Text of the link.

required

url

str | None

A URL to open, when clicked. If None, the text parameter will also be used as the url.

None

tooltip

str | None

Optional tooltip.

None

name

str | None

Name of widget.

None

id

str | None

ID of Widget.

None

classes

str | None

Space separated list of class names.

None

disabled

bool

Whether the static is disabled or not.

False

BINDINGS class-attribute instance-attribute

BINDINGS = [Binding('enter', 'select', 'Open link')]
Key(s) Description
enter Open the link in the browser.