Add download example

This commit is contained in:
Darren Burns
2024-08-14 14:04:16 +01:00
parent 77cdf62db7
commit 5837870c7b

26
examples/download.py Normal file
View File

@@ -0,0 +1,26 @@
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)
self.deliver_text(string_io)
app = ScreenshotApp()
if __name__ == "__main__":
app.run()