Skip to content

SingleChoice-type elements save data as integers - how can I access the corresponding text? #179

Answered by jobrachem
jobrachem asked this question in Alfred Q&A
Discussion options

You must be logged in to vote

Here's an example with extensive comments that walks you through the steps:

import alfred3 as al
exp = al.Experiment()

@exp.member
class Demo(al.Page):
    
    def on_exp_access(self):
        self += al.SingleChoice("a", "b", name="my_single_choice_element")


@exp.member
class Show(al.Page):
    
    def on_first_show(self):
        # This is the SingleChoice element instance
        # The pattern is: self.exp.PAGENAME.ELEMENTNAME
        element = self.exp.Demo.my_single_choice_element 
        
        # This is the number of the selected choice, starting at 1
        selected_choice_number = element.input  
        
        # This is a list of the available choices. These are insta…

Replies: 1 comment

Comment options

jobrachem
Jan 20, 2022
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by jobrachem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant