【问题标题】:kivy executes "on_release"-command multiple timeskivy 多次执行“on_release”命令
【发布时间】:2018-07-13 19:44:06
【问题描述】:

为了触发图像的获取,我使用kivy-buttonon_release 函数。

因此,无论何时单击(或按下 - 因为使用触摸屏)此按钮都会使用gphoto2 触发相机。

问题: 有时,该功能会执行多次(拍摄多张图像),而显然只按了一次。

根据日志,我确信这是与 kivy 相关的问题(与相机等无关):on_release-函数中的日志条目在日志中出现多次。

我正在使用触摸屏在 Ubuntu 14.04 LTS(64 位)下运行带有 kivy(版本 1.9.0)和 python(版本 2.7.6)的应用程序。

欢迎任何有关如何调试或修复问题的提示。

【问题讨论】:

    标签: python ubuntu kivy


    【解决方案1】:

    我被同样的问题困扰了好几天!

    你的代码中有这行吗?

    Config.set('input', 'mouse', 'mouse, multitouch_on_demand')
    

    如果是,则将其删除。

    在触控设备上,触控会被触发多次。

    希望它能帮助遇到同样问题的人。

    【讨论】:

      【解决方案2】:

      您可以在第一个释放事件开始时禁用该按钮,并在拍摄照片的线程结束时再次启用该按钮。这样您就不会执行该按钮的多个事件,但仍允许主应用程序线程继续。

      from kivy.app import App
      from kivy.uix.boxlayout import BoxLayout
      from kivy.lang import Builder
      import time
      import threading
      
      Builder.load_string('''
      
      <MyLayout>:
          Button:
              text: 'Print to terminal'
              on_release: 
                  root.button_released(self)
      ''')
      
      
      class MyLayout(BoxLayout):
      
          def button_released(self,button):
              button.disabled = True
              print("{} pressed!".format(button))
              threading.Thread(target=self.take_picture, args=(button,)).start()
      
          def take_picture(self,button):
              time.sleep(1)  # taking picture or whatever
              button.disabled = False
      
      class MyApp(App):
      
          def build(self):
              return MyLayout()
      
      
      MyApp().run()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-01
        • 2015-11-14
        • 2020-07-08
        • 2012-08-31
        • 2016-11-10
        相关资源
        最近更新 更多