在固定时间后更新python kivy中的线段
我试图创建一行,更新是在一个固定的时间间隔之后(比如5秒)。我写了下面的代码,但它没有更新行。谁能帮我弄清楚是谁干的在固定时间后更新python kivy中的线段,python,kivy,Python,Kivy,我试图创建一行,更新是在一个固定的时间间隔之后(比如5秒)。我写了下面的代码,但它没有更新行。谁能帮我弄清楚是谁干的 from kivy.app import App from kivy.uix.gridlayout import GridLayout from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.graphics import Color, Ellipse, Line import time
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.graphics import Color, Ellipse, Line
import time
from kivy.clock import Clock
class MyWidget(Widget):
def my_callback(dt,ds):
Line(points=[100, 100, 200, 100, 100, 200], width=10)
pass
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
with self.canvas:
self.line = Line(points=[100, 100, 200, 100, 100, 200], width=1)
self.line.width = 2
Clock.schedule_once(self.my_callback, 5)
pass
# add your instruction for main canvas here
with self.canvas.before:
pass
# you can use this to add instructions rendered before
with self.canvas.after:
pass
# you can use this to add instructions rendered after
class LineExtendedApp(App):
def build(self):
root = GridLayout(cols=2, padding=50, spacing=50)
root.add_widget(MyWidget())
return root
if __name__ == '__main__':
LineExtendedApp().run()
my_callback
实际上不是在with
语句中调用的,而是在很久以后调用的,即使是这样,它也不会做你想做的事情-它会画一条新的线,而不是修改现有的线
相反,您可以将my_回调更改为:
self.line.points = [100, 100, 200, 100, 100, 200]
self.line.width = 10
这将根据需要修改现有线。您也可以将时钟调度从with语句中去掉,但只要它停留在\uuuu init\uuuu