В моем тексте может быть несколько ссылок, например:
Код: Выделить всё
Hello [@click=hello]World[/] there, how are you?
This is a test of [@click=more] more info[/] being clickable as well.
ПРИМЕЧАНИЕ. Я также привязал клавишу «b» к почти такому же действию, чтобы видеть, как она работает.
Она должна изменить цвет фона и подзаголовок приложения.
Код: Выделить всё
import os
import sys
from rich.console import RenderableType
from rich.panel import Panel
from rich.text import Text
from textual.app import App
from textual.widgets import Header, Footer, ScrollView
from textual.widgets import Placeholder
class MyApp(App):
async def on_load(self) -> None:
await self.bind("b", "color('blue')")
async def on_mount(self) -> None:
await self.view.dock(Header(), size=5, edge="top")
await self.view.dock(Footer(), edge="bottom")
await self.view.dock(ScrollView(Panel("Hello [@click=hello]World[/] more info here")), edge="top")
async def action_color(self, color:str) -> None:
self.app.sub_title = "KEYBOARD"
self.background = f"on {color}"
async def action_hello(self) -> None:
self.app.sub_title = "CLICKED"
self.background = "on red"
MyApp.run(title="Test click", log="textual.log")
Подробнее здесь: https://stackoverflow.com/questions/714 ... ext-object
Мобильная версия