How can I get ref text when I have many refs in kivy label?

折月煮酒 提交于 2019-12-25 16:42:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!