Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 标签不是';t更新_Python_Multithreading_Python 3.x - Fatal编程技术网

Python 标签不是';t更新

Python 标签不是';t更新,python,multithreading,python-3.x,Python,Multithreading,Python 3.x,Def Timer是一个线程,它在后台持续运行并正在更新(这正在运行) 现在,我需要标签来更新计时器的值。在之后使用: def main(self): timer = Thread(target=self.timer, args=(1, 0)) timer.start() root = Tk() root.title("Jamie Stopwatch") v = IntVar() v.set(self.timed) stopwatch

Def Timer是一个线程,它在后台持续运行并正在更新(这正在运行)


现在,我需要标签来更新计时器的值。

在之后使用

def main(self):
    timer = Thread(target=self.timer, args=(1, 0))
    timer.start()


    root = Tk()
    root.title("Jamie Stopwatch")
    v = IntVar()
    v.set(self.timed)
    stopwatch = ttk.Label(root, textvariable=v)
    stopwatch.grid(row=1, column=2)

您是在问如何解决线程问题,还是在tkinter中编写秒表。在tkinter.root中创建秒表当然不需要线程。在(self.update,100)AttributeError之后:“AO”对象没有属性“update”,我已经给了你
update
-方法,你需要在
AO
-class中插入该方法。耶,root=Tk()是在main(self)中定义的,所以它说找不到root
def main(self):
    timer = Thread(target=self.timer, args=(1, 0))
    timer.start()


    root = Tk()
    root.title("Jamie Stopwatch")
    v = IntVar()
    v.set(self.timed)
    stopwatch = ttk.Label(root, textvariable=v)
    stopwatch.grid(row=1, column=2)
def main(self):
    [...]
    self.stopwatch_value = IntVar()
    stopwatch = ttk.Label(root, textvariable=self.stopwatch_value)
    stopwatch.grid(row=1, column=2)
    root.after(self.update, 500)

def update(self):
    self.stopwatch_value.set(self.timed)
    root.after(self.update, 500)