Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

example: building a textual app in marimo (#4959)

Dylan Madisettiad333ccf8b0c
diff --git a/examples/running_as_a_script/textual_app.py b/examples/running_as_a_script/textual_app.py
new file mode 100644
index 0000000000..cc7a1ac64b
--- /dev/null
+++ b/examples/running_as_a_script/textual_app.py
@@ -0,0 +1,57 @@
+# /// script
+# requires-python = ">=3.13"
+# dependencies = [
+# "marimo",
+# "textual==3.2.0",
+# ]
+# ///
+"""
+Marimo wrapper for the base Textual app example.
+Provides a basic clock widget to show the current time.
+run with `python textual_app.py`
+"""
+
+import marimo
+
+__generated_with = "0.13.10"
+app = marimo.App()
+
+with app.setup:
+ import marimo as mo
+ from datetime import datetime
+
+ from textual.app import App, ComposeResult
+ from textual.widgets import Digits
+
+
+class ClockApp(App):
+ CSS = """
+ Screen { align: center middle; }
+ Digits { width: auto; }
+ """
+
+ def compose(self) -> ComposeResult:
+ yield Digits("")
+
+ def on_ready(self) -> None:
+ self.update_clock()
+ self.set_interval(1, self.update_clock)
+
+ def update_clock(self) -> None:
+ clock = datetime.now().time()
+ self.query_one(Digits).update(f"{clock:%T}")
+
+
+def _():
+ app = ClockApp()
+ if mo.app_meta().mode == "script":
+ app.run()
+ # App gives back a basic repr
+ app
+ return
+
+
+if __name__ == "__main__":
+ app.run()