How can I get ref text when I have many refs in ki

2019-08-31 02:08发布

问题:

Please help. I have many refs in label and when user click on first ref how can i get ref text on main.py? I need python method which can get this ref text.

Label:
     markup: True
     text: "[ref=first ref]First ref[/ref] ,[ref=second ref]Second ref[/ref]"
     on_ref_press: # here I need method that can return ref.text     

回答1:

All the arguments passed to the event handler are available in kv via the args variable. The arguments to the on_ref_press handler are instance, refvalue. So, for example:

Label:
    markup: True
    text: "[ref=first ref]First ref[/ref] ,[ref=second ref]Second ref[/ref]"
    on_ref_press: print args[1]

will cause first ref to be printed when the "First ref" text is clicked, and second ref will be printed when the "Second ref" text is clicked.