how to get selected value of OptionList #3247
Answered
by
davep
MohamedElgamal
asked this question in
Q&A
-
i am trying to get the selected value of OptionList and can't figure out which attribute to get the value @on(OptionList.OptionMessage) def user_selected(self, event: OptionList.OptionMessage): print(f"Option Selected {event}") this is my code snippet to catch the selected value |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Sep 6, 2023
Replies: 1 comment 4 replies
-
Does this help? https://textual.textualize.io/widgets/option_list/#textual.widgets._option_list.OptionList.OptionMessage |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Option
s within anOptionList
don't have a value. The idea behindOptionList
is that it's a list of prompts (options) that the user can select from, and when you have the index of a selection option you can decide to do something with that. For example, you maybe maintaining a parallel list of values and the index can be used to retrieve the value from that.If you wanted to keep a value along with an
Option
in anOptionList
the thing to do would be to subclassOption
for your own needs and then add appropriate properties. For example, in a personal library I maintain, I usedOptionList
as the heart of a filesytem entry picking dialog, and I inherit fromOption
and add lots of properties f…