Python 标签不是';t更新
Def Timer是一个线程,它在后台持续运行并正在更新(这正在运行)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 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)