Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Example for Textualize/textual#4096
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Feb 1, 2024
1 parent 758faa1 commit fbef245
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions reuse_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""https://github.com/Textualize/textual/issues/4096"""

from asyncio import sleep

from textual import on, work
from textual.app import App, ComposeResult
from textual.widgets import Button, ProgressBar

class ReuseProgressApp(App[None]):

def compose(self) -> ComposeResult:
yield Button("Count 10 seconds")
yield ProgressBar()

@on(Button.Pressed)
def start_count(self) -> None:
progress = self.query_one(ProgressBar)
progress.total = 100
progress.progress = 0
self.count()

@work
async def count(self) -> None:
for _ in range(100):
self.query_one(ProgressBar).advance()
await sleep(0.1)

if __name__ == "__main__":
ReuseProgressApp().run()

### reuse_progress.py ends here

0 comments on commit fbef245

Please sign in to comment.