![](/img/trans.png)
[英]Kivy Label: on_touch_down event is triggered everywhere in the screen
[英]On_Release event of bind button in kivy not working - running on_touch_down
我正在嘗試在小部件上添加按鈕並將該按鈕綁定到函數。 同時,我有一個on_touch_down
事件正在運行。
但是,當我按下按鈕時,它不會調用該函數。 而是調用on_touch_down
事件。
我怎樣才能解決這個問題?
import kivy
kivy.require('1.0.8')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
class a(Widget):
def on_touch_down(self, touch):
print("touch x is ", touch.x)
print("touch y is ", touch.y)
def update(self,dt):
print("updated")
class mainApp(App):
def build(self):
print("Hi, I am build function")
parent = a()
self.Startbtn = Button(text='Start')
parent.add_widget(self.Startbtn)
self.Startbtn.bind(on_release=self.Loop1)
#Clock.schedule_interval(parent.update, 10.0/1000 )
return parent
def Loop1(self,dt):
print("Hi, this is Loop function")
self.v=1
if __name__ == '__main__':
mainApp().run()
嘗試這個:
class a(Widget):
def on_touch_down(self, touch):
print "touch x is ",touch.x
print "touch y is ",touch.y
# add this line:
super(a, self).on_touch_down(touch)
on_touch ...方法在觸摸事件鏈中首先執行,將其覆蓋,您會中斷該鏈,因此只需添加super()即可繼續。 希望能有所幫助。
編輯:結果,而不是super(),您可以返回True繼續向下事件樹
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.