Skip to content
Discussion options

You must be logged in to vote

To the best of my knowledge, there isn't an exposed method of simulating a key press. If I'm understanding correctly what you want to do (a yes/no dialog that has yes/no buttons but also handles Y/N key press), I think I'd start with something like this:

from textual.app import App, ComposeResult
from textual.widgets import Static, Button
from textual.containers import Horizontal

class Discussion1129( App[ str ] ):

    CSS = """
    #question {
        border: solid green;
    }

    Button {
        margin: 2;
    }
    """

    BINDINGS = [
        ( "y", "result( 'y' )", "" ),
        ( "n", "result( 'n' )", "" )
    ]

    def compose( self ) -> ComposeResult:
        yield Static( "…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jspv
Comment options

Answer selected by jspv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants