Created
May 1, 2024 15:46
-
-
Save fmaida/6494980ea4b4d3829de4f2694e6b8639 to your computer and use it in GitHub Desktop.
"Greeter" is a very simple app made with Textual. All it does is to "greet" the user in the output field. Enter your name in the "input field" and then push the "Submit" button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textual.app import App, ComposeResult | |
from textual.containers import Horizontal | |
from textual.widgets import Footer, Header, Static, Button, TextArea | |
class MyApp(App): | |
def on_mount(self): | |
self.title = "Greeter" # This line set the app's title | |
def compose(self) -> ComposeResult: | |
yield Header() | |
yield Static("Please enter your name:") # Adds a label | |
with Horizontal(): | |
yield TextArea(id="input", text="Will McGugan") # Add a text field for the name | |
yield Button("Submit", id="submit_name") # Adds a button to submit the name | |
yield Static("The app response:") # Adds a second label | |
yield TextArea(id="output", text="...") # Adds a text field for the output | |
def on_button_pressed(self, event: Button.Pressed) -> None: | |
if event.button.id == "submit_name": | |
name = self.query_one('#input') | |
output = self.query_one("#output") | |
output.text = f"Hello {name.text} !" | |
if __name__ == '__main__': | |
app = MyApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment