问题
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.
来源:https://stackoverflow.com/questions/26302848/how-can-i-get-ref-text-when-i-have-many-refs-in-kivy-label