Howto set RadioSet selection programmatically #4572
Unanswered
UlrichGoebel
asked this question in
Q&A
Replies: 1 comment
-
This looks like a possible bug, rather than something you're doing wrong. I don't yet fully understand the workings of the from textual.app import App, ComposeResult
from textual.widgets import Footer, RadioButton, RadioSet
class ExampleApp(App):
BINDINGS = [("n", "toggle_next_button", "Toggle Next Buttton")]
def compose(self) -> ComposeResult:
with RadioSet():
yield RadioButton("One", id="one", value=True)
yield RadioButton("Two", id="two")
yield RadioButton("Three", id="three")
yield Footer()
def action_toggle_next_button(self) -> None:
radio_set = self.query_one(RadioSet)
assert radio_set._selected == 0
radio_set.action_next_button()
assert radio_set._selected == 1
radio_set.action_toggle_button()
assert radio_set._selected == 1
assert radio_set.pressed_button is not None
# The test below will fail, despite the toggle action seemingly using
# `_selected` attribute as an index?
assert radio_set.pressed_index == 1
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I try to set the actual choice of a
RadioSet
programmatically an struggle in understanding theRadioSet
. To demonstrate my struggeling let's see the following code:It shows a
RadioSet
with three choices, then twoButtons
, one for showing the actual choice, the other to trigger some action(s) on theRadioSet
.The
on_button_pressed
handler should start the action or even two actions, if theAction
button is pressed. Independend which button was pressed it should update the value of theInput
to show the actual/new choice.That is what I expect. But...
Action
Button changes the choice (this can be seen in the terminal) but in theInput
it shows the last choice, not the actual. Why?Show
Button shows the actual choice as expected.action_toggle_button
, so justaction_next_button
is done: Well, the choice doesn' change. That's o.k. But what does it actually?action_next_button
, so justaction_toggle_button
should be done: Clicking theAction
doesn't do anything but showing the actual choice. So it seems that it cant toggle the choice if it is alredy activated - which obviously makes sense in a
RadioSetcontext because it can't know which
RadioButton` has to be the new choice. Does that mean that toggle in fact means set?RadioButton
and choose it.RadioButton
even if it is not the pressed one? Then I could step through theRadioButton
usingaction_next_button
until I found the right one which can then be toggled byaction_toggle_button
, which in fact means it would be the new choice.Can someone help me to understand what's going on here?
Best regards
Ulrich
Beta Was this translation helpful? Give feedback.
All reactions