This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Example for Textualize/textual#4096
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |