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
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I try to set the actual choice of a
RadioSetprogrammatically an struggle in understanding theRadioSet. To demonstrate my struggeling let's see the following code:It shows a
RadioSetwith three choices, then twoButtons, one for showing the actual choice, the other to trigger some action(s) on theRadioSet.The
on_button_pressedhandler should start the action or even two actions, if theActionbutton is pressed. Independend which button was pressed it should update the value of theInputto show the actual/new choice.That is what I expect. But...
ActionButton changes the choice (this can be seen in the terminal) but in theInputit shows the last choice, not the actual. Why?ShowButton shows the actual choice as expected.action_toggle_button, so justaction_next_buttonis done: Well, the choice doesn' change. That's o.k. But what does it actually?action_next_button, so justaction_toggle_buttonshould be done: Clicking theActiondoesn'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 aRadioSetcontext because it can't know whichRadioButton` has to be the new choice. Does that mean that toggle in fact means set?RadioButtonand choose it.RadioButtoneven if it is not the pressed one? Then I could step through theRadioButtonusingaction_next_buttonuntil 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