Skip to main content

A simple spinbox widget for Textual

Project description

A Textual Spinbox widget

Demo a Textual spinbox

Simply run from the repo with uv

uvx --from git+https://github.com/friscorose/textual-spinbox spinbox_demo

now you can scroll wheel up or down, drag up or down and click the up or down arrows to change the value in the spinbox. A simple ctrl+c to quit.

Use uv to build an app

Build a silly app with a custom Textual spinbox widget using uv.

uv init sillyapp

then

cd sillyapp

edit hello.py to contain the following source

from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widgets import Button, Label
from textual_spinbox import SpinBox

class Statement( Label ):
    silly = reactive( "...a silly statement.", recompose=True )

    def compose(self) -> ComposeResult:
        yield Label( self.silly )

class SpinboxApp(App):
    DEFAULT_CSS = """
    SpinBox {
        width: 13;
    }
    """

    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    things = ['albatross', 'boomerang', 'cat', 'dodo', 'ewe', 'flotilla', 'geriatric', 'hopscotch', 'ice flow', 'jalopy', 'Kobayashi Maru', 'lava', 'mycelium', 'narwhal', 'oil tanker', 'pod', 'quaaltagh', 'rat', 'snail', 'tiptoe', 'ukulele', 'verb', 'wheeriemigo', 'xanthippe', 'yill', 'zymurgy']
    def compose(self) -> ComposeResult:
        yield SpinBox( id="pennies" )
        yield SpinBox( range(1,32), id="date" )
        yield SpinBox( self.months, id="month" )
        yield SpinBox( self.things, id="thing" )
        yield Button( "Make", variant="primary", id="make" )
        yield Statement()

    def on_button_pressed(self, event: Button.Pressed):
        if event.button.id == "make":
            pennies = self.query_one("#pennies").value
            date = self.query_one("#date").value
            month = self.query_one("#month").value
            thing = self.query_one("#thing").value
            self.query_one("Statement").silly = f"""\
...my bank statement change by {pennies} cents on {month}/{date} \n\
Reason: compulsory {thing} race gambling."""

def exec_main():
    app = SpinboxApp()
    app.run() 

if __name__ == "__main__":
    exec_main()

make Textual available to the app

uv add textual

then make the textual-spinbox widget available

uv add "textual-spinbox @ git+https://github.com/friscorose/textual-spinbox"

now run it

uv run hello.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_spinbox-0.7.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_spinbox-0.7.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file textual_spinbox-0.7.0.tar.gz.

File metadata

  • Download URL: textual_spinbox-0.7.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.3

File hashes

Hashes for textual_spinbox-0.7.0.tar.gz
Algorithm Hash digest
SHA256 98d9c102fd408827151def68a66cc41c96472a28ae35219ce211493e7c3967a0
MD5 02dea2744218452dc45a51aae7d771b3
BLAKE2b-256 4dff99aa64568720eec23c714cff34b4c2abdffbcf6f0b4b7b730d7c746b5878

See more details on using hashes here.

File details

Details for the file textual_spinbox-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_spinbox-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d59b89a204d76536d484ef3d2818bff5cad334a5553bbf0939ea048e0cf07ea
MD5 92ae73fefea18e05469dc1a33efb5908
BLAKE2b-256 cd9165eb065b1884ba9095a453f551d33e3ab5aab50df11be6cda5bf52b73c15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page