• <tfoot id='BeD8y'></tfoot>

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

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

      1. Python/Kivy:我可以在双击标签时调用函数吗

        时间:2023-10-09

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

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

                • <bdo id='BEEXM'></bdo><ul id='BEEXM'></ul>
                  <tfoot id='BEEXM'></tfoot>
                    <tbody id='BEEXM'></tbody>
                • <i id='BEEXM'><tr id='BEEXM'><dt id='BEEXM'><q id='BEEXM'><span id='BEEXM'><b id='BEEXM'><form id='BEEXM'><ins id='BEEXM'></ins><ul id='BEEXM'></ul><sub id='BEEXM'></sub></form><legend id='BEEXM'></legend><bdo id='BEEXM'><pre id='BEEXM'><center id='BEEXM'></center></pre></bdo></b><th id='BEEXM'></th></span></q></dt></tr></i><div id='BEEXM'><tfoot id='BEEXM'></tfoot><dl id='BEEXM'><fieldset id='BEEXM'></fieldset></dl></div>
                  本文介绍了Python/Kivy:我可以在双击标签时调用函数吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  谁能告诉我如何在双击标签 Item1,Item2 时调用函数 def demo() ?

                  Can someone tell me how to call function def demo() on double click of Label Item1,Item2 ?

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.screenmanager import Screen
                  
                  def convert_data(data):
                      l = []
                      for item in data:
                          for key, value in item.items():
                              l.append({'text': key, 'value': value})
                      return l
                  
                  class test():
                  
                      def demo(self):
                          print('Demo')
                  
                  class Invoice(Screen):
                      def abc(self):
                          arr = ({'Item1': ''},{'Item2': 1000})
                  
                          self.rv.data = convert_data(arr)
                  
                  class MyApp(App):
                      def build(self):
                          return Builder.load_file('test.kv')
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  test.kv

                  <Button@Button>:
                      font_size: 15
                      size_hint_y:None
                      height: 30
                  
                  <Label@Label>:
                      font_size: 15
                      size_hint_y:None
                      height: 30
                  
                  <Item@GridLayout>:
                      cols: 2
                      text: ""
                      value: 0
                      padding : 5, 0
                      spacing: 10, 0
                      Label:
                          size_hint_x: .35
                          text: root.text
                          halign: 'left'
                          valign: 'middle'
                          canvas.before:
                              Color:
                                  rgb: .6, .6, .6
                              Rectangle:
                                  pos: self.pos
                                  size: self.size
                  
                      Label:
                          size_hint_x: .15
                          text: str(root.value)
                          halign: 'right'
                          valign: 'middle'
                          canvas.before:
                              Color:
                                  rgb: .6, .6, .6
                              Rectangle:
                                  pos: self.pos
                                  size: self.size
                  
                  Invoice:
                      rv: rv
                      BoxLayout:
                          orientation: "vertical"
                          padding : 15, 15
                  
                          BoxLayout:
                              orientation: "vertical"
                              padding : 5, 5
                              size_hint: .6, None
                              pos_hint: {'x': .18,}
                  
                  
                              BoxLayout:
                                  orientation: "horizontal"
                                  padding : 5, 5
                                  spacing: 10, 10
                                  size: 800, 40
                                  size_hint: 1, None
                  
                                  Button:
                                      text: "Show"
                                      size_hint_x: .05
                                      spacing_x: 30
                                      on_press:root.abc()
                  
                          BoxLayout:
                              orientation: "horizontal"
                              size_hint: 1, 1
                  
                              BoxLayout:
                                  orientation: "vertical"
                                  size_hint: .5, 1
                                  padding : 0, 15
                                  spacing: 10, 10
                                  size: 500, 30
                  
                  
                                  BoxLayout:
                                      RecycleView:
                                          id: rv
                                          viewclass: 'Item'
                                          RecycleBoxLayout:
                                              default_size: None, dp(30)
                                              default_size_hint: 1, None
                                              size_hint_y: None
                                              height: self.minimum_height
                                              orientation: 'vertical'
                  

                  推荐答案

                  你可以为你的 Label 创建一个子类并附加 double_tap 事件

                  you can create a subclass of your Label and attach the double_tap event to it

                  class MyLabel(Label):
                      def on_touch_down(self, touch):
                          if touch.is_double_tap:
                              demo()
                  

                  这篇关于Python/Kivy:我可以在双击标签时调用函数吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Python透明KivyMD导航抽屉 下一篇:如何在kivy中使用阻塞MessgeBox

                  相关文章

                  最新文章

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

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

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