如何为微调框选择kivy旧值 [英] How to select kivy old value for the spinner

查看:52
本文介绍了如何为微调框选择kivy旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kivy文档指出,触摸微调器会显示一个下拉菜单,其中包含所有其他可用值,用户可以从中选择一个新的值."是否有任何变通办法来判断用户为执行相同操作而选择的旧值?我真的很坚持这一点,请帮帮我.

Kivy documentation states that "Touching the spinner displays a dropdown menu with all the other available values from which the user can select a new one." Is there any workaround to tell if it is an old value a user selected in order to perform the same action? I am really stuck with this, please help me out.

推荐答案

您可以使用构成DropDownButtons来触发想要使用的任何方法,而不是使用on_texton_select跑.这样,是否选择相同的Button都没有关系.这是该方法的一个简单示例:

Rather than using the on_text or on_select, you can use the Buttons that make up the DropDown to trigger whatever method you want to run. That way, it doesn't matter whether the same Button is selected or not. Here is a simple example of that approach:

from kivy.app import App
from kivy.lang import Builder

kv = '''
#:import Factory kivy.factory.Factory

<MySpinnerOption@SpinnerOption>:
    on_release: app.spinner_selected(self.text)

RelativeLayout:
    Spinner:
        text: 'Choose One'
        size_hint: 0.2, 0.2
        pos_hint: {'center_x':0.5, 'center_y':0.5}
        option_cls: Factory.get('MySpinnerOption')
        values: ['1', '2', '3']
        # on_text: app.spinner_selected(self.text)   # not needed
'''

class TestApp(App):
    def build(self):
        return Builder.load_string(kv)

    def spinner_selected(self, text):   # whatever method you want to run
        print('spinner selected:', text)

TestApp().run()

上面的代码将SpinnerDropDown中的Buttonson_release设置为通常使用'on_text分配的方法.现在,只要释放Buttons之一,该方法就会被调用.

The above code sets the on_release of the Buttons in the DropDown of the Spinner to the method that you would normally assign using 'on_text. Now, that method will be called whenever one of the Buttons is released.

这篇关于如何为微调框选择kivy旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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