• <bdo id='IZAbv'></bdo><ul id='IZAbv'></ul>
      <tfoot id='IZAbv'></tfoot>

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

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

      1. <legend id='IZAbv'><style id='IZAbv'><dir id='IZAbv'><q id='IZAbv'></q></dir></style></legend>
      2. 具有多项选择的 kivy 微调器小部件

        时间:2023-06-06
            <tbody id='2vEd2'></tbody>

          <tfoot id='2vEd2'></tfoot>

          <small id='2vEd2'></small><noframes id='2vEd2'>

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

              • <bdo id='2vEd2'></bdo><ul id='2vEd2'></ul>

                <legend id='2vEd2'><style id='2vEd2'><dir id='2vEd2'><q id='2vEd2'></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 微调器小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文章

                  1. <tfoot id='AMIZS'></tfoot>

                  2. <small id='AMIZS'></small><noframes id='AMIZS'>

                    • <bdo id='AMIZS'></bdo><ul id='AMIZS'></ul>

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