How to get the parent class of widget when on click is fired #3198
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
I'm struggling to follow the question, or quite see how it relates to the title of the discussion, but to answer the question in the title: a widget's parent is available by its As for the main body of the question above, do you think you could try and make a small stand-alone example of what it is you want to do and explain what's not working? |
Beta Was this translation helpful? Give feedback.
-
what i want when the checkbox is clicked to access the member attribute of the class who composed the checkbox to sent it to database class StateItem(Static): def __init__(self, value): super().__init__() self.saved_value = value def compose(self) -> ComposeResult: yield Horizontal( Label(id="issue-type", renderable=self.request.get_type()) , Checkbox(classes="issue-checkbox") , id="horizontal-con" ) def on_mount(self): pass @on(Checkbox.Changed, ".issue-checkbox") def state_request_checkbox_clicked(self, event): // i want to get the saved_value attribute of StateItem here database.sendvalue(self.saved_value) self.remove() |
Beta Was this translation helpful? Give feedback.
-
when i tried self.saved_value the returned value is None so i think the self keyword in state_request_checkbox_clicked is relate to checkbox class not StateIten |
Beta Was this translation helpful? Give feedback.
-
i figured out the problem i forget brackets |
Beta Was this translation helpful? Give feedback.
I'm afraid that doesn't really clarify the question. In that example code
state_request_checkbox_clicked
is a method ofStateItem
, soself.saved_value
would be thesaved_value
attribute of the widget thatcomposed
theCheckbox
.