【发布时间】:2020-04-11 22:58:34
【问题描述】:
我编写了一个小代码来使用 on_touch_move 事件水平拖动小部件。甚至我的小部件水平移动。但是当我拖动小部件时,会生成以下日志。”[CRITICAL] [Clock ] 警告,在下一帧之前完成了太多迭代。检查您的代码,或增加 Clock.max_iteration 属性 em>”。 请在下面找到我的示例代码。要重现这种情况,只需左右拖动白色小部件。上面的日志消息被打印出来。
from kivy.app import App
from kivy.graphics import Rectangle
from kivy.uix.scatter import Scatter
from kivy.uix.relativelayout import RelativeLayout
class MyPaintWidget(Scatter):
def __init__(self, **kwargs) :
super(MyPaintWidget, self).__init__(**kwargs)
def on_touch_move(self, touch):
touch_x_hint = touch.x / self.parent.size[0]
self.pos_hint = {'center_x': touch_x_hint }
return super(Scatter, self).on_touch_move(touch)
class MyPaintApp(App):
def build(self):
parent = RelativeLayout()
Wdgt = MyPaintWidget(pos_hint={'center_x':0.5, 'center_y':0.5}, size_hint=(0.2,0.2))
with Wdgt.canvas:
Rectangle(pos_hint = {'center_x':0.5, 'center_y':0.5}, size = (Wdgt.width, Wdgt.height))
parent.add_widget(Wdgt)
return parent
if __name__ == '__main__':
MyPaintApp().run()
【问题讨论】: