mirror of
https://github.com/Textualize/textual-web.git
synced 2025-10-17 02:36:40 +03:00
25 lines
768 B
Python
25 lines
768 B
Python
from textual import on
|
|
from textual.app import App, ComposeResult
|
|
from textual.widgets import Button
|
|
|
|
|
|
class OpenLink(App[None]):
|
|
"""Demonstrates opening a URL in the same tab or a new tab."""
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield Button("Visit the Textual docs", id="open-link-same-tab")
|
|
yield Button("Visit the Textual docs in a new tab", id="open-link-new-tab")
|
|
|
|
@on(Button.Pressed)
|
|
def open_link(self, event: Button.Pressed) -> None:
|
|
"""Open the URL in the same tab or a new tab depending on which button was pressed."""
|
|
self.open_url(
|
|
"https://textual.textualize.io",
|
|
new_tab=event.button.id == "open-link-new-tab",
|
|
)
|
|
|
|
|
|
app = OpenLink()
|
|
if __name__ == "__main__":
|
|
app.run()
|