Skip to content
Discussion options

You must be logged in to vote

Here's a couple of possible solutions:

class ScreenOne(Screen):
    """Solution 1: Instead add a Binding to map the key press"""
    # BINDINGS = [("enter", "app.push_screen('two')")]

    def compose(self) -> ComposeResult:
        yield Static("Press Enter to push ScreenTwo.")

    def on_key(self, event: events.Key) -> None:
        if event.key == "enter":
            """Solution 2: Stop the event from propagating"""
            # event.stop()
            app.push_screen("two")

I think the problem is that the on_key event is never actually processed on your first screen, so the event is passed to your App which then triggers clicking the first button.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by maxigaz
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