-
Hey, I'm trying to build a text based game with textual which is driven by the keyboard. I'm trying to get a markdown element to update the text displayed when the user presses the keyboard. So far I have not found a way to trigger a widget on a keyboard press. It only appears possible to trigger the main application. There are many ways to trigger a widget when you click on it, but my application is not intended to involve the mouse at all. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Here is some example code I have tried which does not work.
|
Beta Was this translation helpful? Give feedback.
-
Have you looked into https://textual.textualize.io/guide/input/ ? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
@Sevii
This isn't the case. As you'll see throughout our own codebase, and in many Textual applications, keyboard bindings can be created on the App, on a screen or on a widget. The thing to note though is that for a keyboard binding to be able to work on a widget the widget needs to be capable of being focused, and of course the binding only works when the widget has focus.
The same is true for keyboard events too.
You can read about this and more in the guide to input in Textual.
To illustrate all of this, here's a version of your initial example…