Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在固定时间后更新python kivy中的线段_Python_Kivy - Fatal编程技术网

在固定时间后更新python kivy中的线段

在固定时间后更新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

我试图创建一行,更新是在一个固定的时间间隔之后(比如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.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