mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add success/warning/error button variants
This commit is contained in:
committed by
Will McGugan
parent
7c33bf9937
commit
8d6a4adff8
@@ -1,12 +1,4 @@
|
||||
#foo {
|
||||
text-style: underline;
|
||||
background: rebeccapurple;
|
||||
}
|
||||
|
||||
*:focus {
|
||||
tint: yellow 50%;
|
||||
}
|
||||
|
||||
#foo:hover {
|
||||
background: greenyellow;
|
||||
Button {
|
||||
padding-left: 1;
|
||||
padding-right: 1;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
from textual import layout, events
|
||||
from textual.app import App, ComposeResult
|
||||
|
||||
from textual.widgets import Button
|
||||
from textual import layout
|
||||
|
||||
|
||||
class ButtonsApp(App[str]):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield layout.Vertical(
|
||||
Button("foo", id="foo"),
|
||||
Button("bar", id="bar"),
|
||||
Button("baz", id="baz"),
|
||||
Button("default", id="foo"),
|
||||
Button.success("success", id="bar"),
|
||||
Button.warning("warning", id="baz"),
|
||||
Button.error("error", id="baz"),
|
||||
)
|
||||
|
||||
def handle_pressed(self, event: Button.Pressed) -> None:
|
||||
self.app.bell()
|
||||
self.log("pressed", event.button.id)
|
||||
self.exit(event.button.id)
|
||||
print("pressed", event.button.id)
|
||||
|
||||
async def on_key(self, event: events.Key) -> None:
|
||||
await self.dispatch_key(event)
|
||||
|
||||
def key_a(self):
|
||||
print(f"text-success: {self.stylesheet.variables.get('text-success')}")
|
||||
print(
|
||||
f"text-success-darken-1: {self.stylesheet.variables.get('text-success-darken-1')}"
|
||||
)
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = ButtonsApp(
|
||||
|
||||
Reference in New Issue
Block a user