mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added remove random button
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import random
|
||||
|
||||
from textual import layout
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Button, Static
|
||||
@@ -38,6 +40,7 @@ class AddRemoveApp(App):
|
||||
layout.Horizontal(
|
||||
Button("Add", variant="success", id="add"),
|
||||
Button("Remove", variant="error", id="remove"),
|
||||
Button("Remove random", variant="warning", id="remove_random"),
|
||||
id="buttons",
|
||||
),
|
||||
layout.Vertical(id="items"),
|
||||
@@ -54,6 +57,11 @@ class AddRemoveApp(App):
|
||||
if things:
|
||||
things.last().remove()
|
||||
|
||||
elif event.button.id == "remove_random":
|
||||
things = self.query("#items Thing")
|
||||
if things:
|
||||
random.choice(things).remove()
|
||||
|
||||
self.app.bell()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user