当我在基维标签中有很多裁判时,如何获得裁判文本? [英] How can I get ref text when I have many refs in kivy label?

查看:81
本文介绍了当我在基维标签中有很多裁判时,如何获得裁判文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助. 我的标签中有很多参考,当用户单击第一个参考时,如何在main.py上获取参考文本? 我需要可以获取此引用文本的python方法.

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     

推荐答案

传递给事件处理程序的所有参数都可以通过args变量在kv中使用. on_ref_press处理程序的参数为instance, refvalue.因此,例如:

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]

将导致在单击第一个参考"文本时打印first ref,并且在单击第二个参考"文本时打印second ref.

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.

这篇关于当我在基维标签中有很多裁判时,如何获得裁判文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆