<tfoot id='n8n0j'></tfoot>
    1. <small id='n8n0j'></small><noframes id='n8n0j'>

      <legend id='n8n0j'><style id='n8n0j'><dir id='n8n0j'><q id='n8n0j'></q></dir></style></legend>
        <bdo id='n8n0j'></bdo><ul id='n8n0j'></ul>

    2. <i id='n8n0j'><tr id='n8n0j'><dt id='n8n0j'><q id='n8n0j'><span id='n8n0j'><b id='n8n0j'><form id='n8n0j'><ins id='n8n0j'></ins><ul id='n8n0j'></ul><sub id='n8n0j'></sub></form><legend id='n8n0j'></legend><bdo id='n8n0j'><pre id='n8n0j'><center id='n8n0j'></center></pre></bdo></b><th id='n8n0j'></th></span></q></dt></tr></i><div id='n8n0j'><tfoot id='n8n0j'></tfoot><dl id='n8n0j'><fieldset id='n8n0j'></fieldset></dl></div>

      具有多项选择的 kivy 微调器小部件

      时间:2023-10-09

          <tbody id='yBOJE'></tbody>
          • <bdo id='yBOJE'></bdo><ul id='yBOJE'></ul>
            <tfoot id='yBOJE'></tfoot>
              <i id='yBOJE'><tr id='yBOJE'><dt id='yBOJE'><q id='yBOJE'><span id='yBOJE'><b id='yBOJE'><form id='yBOJE'><ins id='yBOJE'></ins><ul id='yBOJE'></ul><sub id='yBOJE'></sub></form><legend id='yBOJE'></legend><bdo id='yBOJE'><pre id='yBOJE'><center id='yBOJE'></center></pre></bdo></b><th id='yBOJE'></th></span></q></dt></tr></i><div id='yBOJE'><tfoot id='yBOJE'></tfoot><dl id='yBOJE'><fieldset id='yBOJE'></fieldset></dl></div>

            • <small id='yBOJE'></small><noframes id='yBOJE'>

            • <legend id='yBOJE'><style id='yBOJE'><dir id='yBOJE'><q id='yBOJE'></q></dir></style></legend>
              • 本文介绍了具有多项选择的 kivy 微调器小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在寻找微调器(或类似的东西)类型的 kivy 小部件(最好在 python + kv 文件中),例如,我可以通过复选框选择多个项目.所选项目应在元组 (?) 中可用.

                I am looking for a kivy widget (preferrably in python + kv file) of type spinner (or something alike) where I can select multiple items through a checkbox for example. The selected items should become available in a tuple (?).

                在图片start.png中你会发现开始的情况.

                In the picture start.png you will find the starting situation.

                在表单中有一个标签和一个文本输入字段.单击时应弹出一个包含可用选项的列表.为此,我正在使用 Spinner 小部件.见图片select.png

                In a form there is a label and a Textinput field. On click a list with available options should popup. For this I am using a Spinner widget. See picture select.png

                我想从此列表中选择多个项目.在Nederlands"旁边的示例中,我选择了English".

                From this list I want to select multiple items. In the example next to 'Nederlands' I have selected 'English'.

                完成后,文本输入字段应在逗号分隔列表中显示所选项目.见图片结果.png

                When done, the Text input field should show the selected items in a comma separated list. See picture result.png

                我已经在 e ListView 中使用多选模式进行了尝试.但是 ListView 绑定在 Textfield 区域中.我试图将 ListView 放在弹出窗口中.但这无论出于何种原因都行不通....

                I have tried this with e ListView using the multiple selection mode. But the ListView is bound in the Textfield area. I have tried to put the ListView in a popup window. But this doesn't work-out either for some or other reason....

                非常感谢任何建议.提前致谢.

                Any suggestions are highly appreciated. Thanks in advance.

                推荐答案

                Kivy 默认没有这样的小部件,但是使用 Button+DropDown+ToggleButton 很容易创建自定义.

                Kivy does not have such widget by default, but it is quite easy to create the custom one using Button+DropDown+ToggleButton.

                from kivy.base import runTouchApp
                from kivy.lang import Builder
                from kivy.factory import Factory
                from kivy.properties import ListProperty, ObjectProperty
                from kivy.uix.dropdown import DropDown
                from kivy.uix.button import Button
                
                class MultiSelectSpinner(Button):
                    """Widget allowing to select multiple text options."""
                
                    dropdown = ObjectProperty(None)
                    """(internal) DropDown used with MultiSelectSpinner."""
                
                    values = ListProperty([])
                    """Values to choose from."""
                
                    selected_values = ListProperty([])
                    """List of values selected by the user."""
                
                    def __init__(self, **kwargs):
                        self.bind(dropdown=self.update_dropdown)
                        self.bind(values=self.update_dropdown)
                        super(MultiSelectSpinner, self).__init__(**kwargs)
                        self.bind(on_release=self.toggle_dropdown)
                
                    def toggle_dropdown(self, *args):
                        if self.dropdown.parent:
                            self.dropdown.dismiss()
                        else:
                            self.dropdown.open(self)
                
                    def update_dropdown(self, *args):
                        if not self.dropdown:
                            self.dropdown = DropDown()
                        values = self.values
                        if values:
                            if self.dropdown.children:
                                self.dropdown.clear_widgets()
                            for value in values:
                                b = Factory.MultiSelectOption(text=value)
                                b.bind(state=self.select_value)
                                self.dropdown.add_widget(b)
                
                    def select_value(self, instance, value):
                        if value == 'down':
                            if instance.text not in self.selected_values:
                                self.selected_values.append(instance.text)
                        else:
                            if instance.text in self.selected_values:
                                self.selected_values.remove(instance.text)
                
                    def on_selected_values(self, instance, value):
                        if value:
                            self.text = ', '.join(value)
                        else:
                            self.text = ''
                
                
                kv = '''
                BoxLayout:
                    orientation: 'vertical'
                
                    BoxLayout:
                
                        Label:
                            text: 'Select city'
                
                        MultiSelectSpinner:
                            id: city
                            values: 'Sydney', 'Moscow', 'Warsaw', 'New York', 'Tokio'
                
                    BoxLayout:
                
                        Label:
                            text: 'Select your favorite food'
                
                        MultiSelectSpinner:
                            id: food
                            values: 'Fish and chips', 'Hot-dog', 'Hamburger'
                
                    Label:
                        text: 'You selected {} cities and {} as your favourite food.'.format(city.text, food.text)
                
                <MultiSelectOption@ToggleButton>:
                    size_hint: 1, None
                    height: '48dp'
                
                '''
                
                runTouchApp(Builder.load_string(kv))
                

                这篇关于具有多项选择的 kivy 微调器小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Kivy 和 android 共享首选项 下一篇:Python,Kivy,“AssertionError: None is not callable"按

                相关文章

                最新文章

                    <bdo id='shoxO'></bdo><ul id='shoxO'></ul>

                  1. <i id='shoxO'><tr id='shoxO'><dt id='shoxO'><q id='shoxO'><span id='shoxO'><b id='shoxO'><form id='shoxO'><ins id='shoxO'></ins><ul id='shoxO'></ul><sub id='shoxO'></sub></form><legend id='shoxO'></legend><bdo id='shoxO'><pre id='shoxO'><center id='shoxO'></center></pre></bdo></b><th id='shoxO'></th></span></q></dt></tr></i><div id='shoxO'><tfoot id='shoxO'></tfoot><dl id='shoxO'><fieldset id='shoxO'></fieldset></dl></div>
                    <tfoot id='shoxO'></tfoot>

                    <small id='shoxO'></small><noframes id='shoxO'>

                    <legend id='shoxO'><style id='shoxO'><dir id='shoxO'><q id='shoxO'></q></dir></style></legend>