【问题标题】:Can't get the value for the location of the touch through the .kv file无法通过.kv文件获取触摸位置的值
【发布时间】:2022-01-23 06:51:59
【问题描述】:

main.py

from kivy.app import App
class Main(App):
   def touched(self,touch):
      print(touch)

if __name__ == '__main__':
   Main().run()

main.kv

FloatLayout:
    on_touch_move:app.touched(touch)

NameError: name 'touch' is not defined

【问题讨论】:

    标签: python python-3.x kivy kivy-language


    【解决方案1】:

    您可以在kv 中使用args

    FloatLayout:
        on_touch_move: app.touched(*args)
    

    请参阅documentation

    然后touched()方法可以定义为:

    def touched(self, instance, touch):
        print(touch)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多