Files
textual-serve/examples/download_screenshot.py
2024-08-13 11:46:27 +01:00

28 lines
741 B
Python

import io
from textual import on
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Button
class ScreenshotApp(App[None]):
BINDINGS = [Binding("s", "deliver_screenshot", "Screenshot")]
def compose(self) -> ComposeResult:
yield Button("Hello, World!")
@on(Button.Pressed)
def on_button_pressed(self) -> None:
self.action_deliver_screenshot()
def action_deliver_screenshot(self) -> None:
screenshot_string = self.export_screenshot()
string_io = io.StringIO(screenshot_string)
print(isinstance(string_io, io.TextIOBase))
self.deliver_text(string_io)
app = ScreenshotApp()
if __name__ == "__main__":
app.run()