from textual.app import App, ComposeResult from textual.widgets import Placeholder, Static, Button, Digits from textual.containers import Container, VerticalScroll from textual import events, on from textual.reactive import Reactive, var from textual.css.query import NoMatches from itertools import cycle hellos = cycle( [ "Hola", "Bonjour", "Guten tag", "Salve", "Nǐn hǎo", "Olá", "Asalaam alaikum", "Konnichiwa", "Anyoung haseyo", "Zdravstvuyte", "Hello", ] ) class Hello(Static): # Display a greeting. DEFAULT_CSS = """ Hello { width: 40; height: 9; padding: 1 2; background: $panel; border: $secondary tall; content-align: center middle; } """ def on_mount(self) -> None: self.next_word() def on_click(self) -> None: self.next_word() def next_word(self) -> None: # Get a new hello and update the content area. hello = next(hellos) self.update(f"{hello}, [b]World[/b]!") class MyApp(App): value = var("") """ async def startup(self): await self.bind("q", "action_quit") await self.push_view(self.control) # Left area with numbers numbers = "\n".join(str(i) for i in range(1, 501)) self.view.grid.set_focus("content") h = Hello() self.view.add_right( #VerticalScroll(StrContent(numbers), name="Numbers"), h, width=50, padding=(0,1), ) # Right area with lorem ipsum placeholder lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." self.view.add_right( # VerticalScroll(StrContent(lorem_ipsum), name="Lorem"), Static(lorem_ipsum, name="Lorem"), width=50, padding=(0,1), ) # Command input at the bottom self.view.add_bottom(Static("Enter command: "), height=3) """ def action_quit(self): self.exit() """ class CanvasApp(App): # A Textual app to manage canvas. BINDINGS = [("d", "toggle_dark", "Toggle dark mode")] def compose(self) -> ComposeResult: # Create child widgets for the app. yield Header() yield Footer() def quit(self): self.exit() def action_toggle_dark(self) -> None: # An action to toggle dark mode. self.dark = not self.dark """ def text_app(): app = MyApp() app.run() text_app()