Skip to content

toggle("disabled") was executed by parent widget #5451

@python-and-novella

Description

@python-and-novella

In following code, when I click button'1' ,its parent widget which is horizontal container runs toggle("disabled") but not button'1'.
But, when I click button'2', button'2' runs toggle("disabled"). Do I miss something? https://textual.textualize.io/guide/actions/#namespaces says Textual will look for action methods in the class where they are defined (App, Screen, or Widget), This makes me confused. Thanks someone who can help me in advance.

from textual.app import App
from textual.widgets import Button
from textual.containers import Horizontal

class MyApp(App):
    def on_mount(self):
        self.widgets = [
            Horizontal(
            Button('1',action='toggle("disabled")'),
            Button('2',action='focused.toggle("disabled")'),
            Button('3')
            ),
            Button('4')
        ]
        self.mount_all(self.widgets)


if __name__ == '__main__':
    app = MyApp()
    app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions