标签不是更新

时间:2016-06-05 14:01:47

标签: python multithreading python-3.x

def timer(self, delay, counter):
        while self.exitPro == False:
            while self.isOn:
                time.sleep(delay)
                counter += 1
                self.timed = counter
                print(self.timed)

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)

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

1 个答案:

答案 0 :(得分:0)

使用after

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)