Skip to content

Is it possible to override default widget bindings? #4576

Answered by TomJGooding
asmith26 asked this question in Q&A
Discussion options

You must be logged in to vote

Bindings are inherited by default, so you don't need to mess with __init__. Here's a quick example - notice that the arrow keys still work to navigate the table:

from textual.widgets import DataTable
from textual.app import App, ComposeResult


class ViLikeDataTable(DataTable):
    BINDINGS = [
        ("j", "cursor_down", "Down"),
        ("k", "cursor_up", "Up"),
        ("h", "cursor_left", "Left"),
        ("l", "cursor_right", "Right"),
    ]


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        yield ViLikeDataTable()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_columns("C1", "C2", "C3")
        table.add_row(*("R1C1", 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by asmith26
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