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

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

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

        编写 MDDropdownMenu 项

        时间:2023-10-10
        <i id='9psv4'><tr id='9psv4'><dt id='9psv4'><q id='9psv4'><span id='9psv4'><b id='9psv4'><form id='9psv4'><ins id='9psv4'></ins><ul id='9psv4'></ul><sub id='9psv4'></sub></form><legend id='9psv4'></legend><bdo id='9psv4'><pre id='9psv4'><center id='9psv4'></center></pre></bdo></b><th id='9psv4'></th></span></q></dt></tr></i><div id='9psv4'><tfoot id='9psv4'></tfoot><dl id='9psv4'><fieldset id='9psv4'></fieldset></dl></div>
          • <bdo id='9psv4'></bdo><ul id='9psv4'></ul>

            1. <tfoot id='9psv4'></tfoot>
              <legend id='9psv4'><style id='9psv4'><dir id='9psv4'><q id='9psv4'></q></dir></style></legend>

                  <small id='9psv4'></small><noframes id='9psv4'>

                    <tbody id='9psv4'></tbody>

                • 本文介绍了编写 MDDropdownMenu 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试在 MDDropdownMenu 中写入所选项目.但是,即使有这段代码,我也找不到menu.bind (.....) 函数没有任何结果

                  I try to write the selected item in MDDropdownMenu. But, even with this code, I don't find it I don't have any result with menu.bind (.....) function

                  from kivymd.app import MDApp
                  from kivymd.uix.menu import MDDropdownMenu
                  from kivy.lang import Builder
                  from kivy.clock import Clock
                  from kivymd.uix.screen import Screen
                  
                  
                  KV = """
                  <BuildApp>:
                  
                      MDRaisedButton:
                          id: button
                          text: "PRESS ME"
                          pos_hint: {"center_x": .5, "center_y": .5}
                          on_release: root.menu.open()
                  
                  BuildApp:
                  """
                  
                  class BuildApp(Screen):
                      def __init__(self, **kwargs):
                          super().__init__(**kwargs)
                          Clock.schedule_once(self._late_init)
                  
                      def _late_init(self, interval):
                          menu_items = [{"text": f"Item {i}"} for i in range(5)]
                          self.menu = MDDropdownMenu(
                              caller=self.ids.button,
                              items=menu_items,
                              width_mult=4,
                          )
                          self.menu.bind(on_release=self.menu_callback)
                  
                  
                  
                      def menu_callback(self, instance_menu, instance_menu_item):
                          print(instance_menu, instance_menu_item)
                  
                  
                  class MainApp(MDApp):
                      def build(self):
                          self.root = Builder.load_string(KV)
                  
                  
                  MainApp().run()
                  

                  另外,如何在.Kv文件中编写MDDropdownMenu部分

                  In addition, how can I write the MDDropdownMenu part in .Kv file

                  最好的问候

                  推荐答案

                  使用MDDropdownMenucallback属性:

                  def _late_init(self, interval):
                      menu_items = [{"text": f"Item {i}"} for i in range(5)]
                      self.menu = MDDropdownMenu(
                          caller=self.ids.button,
                          items=menu_items,
                          callback=self.menu_callback,
                          width_mult=4,
                      )
                  
                  def menu_callback(self,instance_menu_item):
                      print(instance_menu_item.text)
                  

                  你可以在kv中定义下拉菜单,像这样:

                  You can define the drop down menu in the kv, like this:

                  from kivymd.app import MDApp
                  from kivymd.uix.menu import MDDropdownMenu
                  from kivy.lang import Builder
                  from kivy.clock import Clock
                  from kivymd.uix.screen import Screen
                  
                  
                  KV = """
                  <MyMenu>:
                      items: [{'text':'item 0'}, {'text':'item 1'}, {'text':'item 2'}, {'text':'item 3'}, {'text':'item 4'}]
                      caller: app.root.ids.button
                      callback: app.root.menu_callback
                      width_mult: 4
                  
                  <BuildApp>:
                      MDRaisedButton:
                          id: button
                          text: "PRESS ME"
                          pos_hint: {"center_x": .5, "center_y": .5}
                          on_release: root.menu.open()
                  
                  BuildApp:
                  """
                  
                  class MyMenu(MDDropdownMenu):
                      pass
                  
                  
                  class BuildApp(Screen):
                  
                      def menu_callback(self, instance_menu_item):
                          print(instance_menu_item.text)
                  
                  
                  class MainApp(MDApp):
                      def build(self):
                          root = Builder.load_string(KV)
                          Clock.schedule_once(self.build_menu)
                          return root
                  
                      def build_menu(self, dt):
                          # cannot create menu until after app is built because of references to app.root in kv
                          self.root.menu = MyMenu()
                  
                  
                  MainApp().run()
                  

                  这篇关于编写 MDDropdownMenu 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有回调的 kivy Urlrequest 在移动设备上抛出错误, 下一篇:Kivy AttributeError:“超级"对象在 ScreenManager 中没

                  相关文章

                  最新文章

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

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

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

                      <tfoot id='jHqRU'></tfoot>
                    1. <legend id='jHqRU'><style id='jHqRU'><dir id='jHqRU'><q id='jHqRU'></q></dir></style></legend>