【发布时间】:2021-08-02 19:23:26
【问题描述】:
有人可以告诉我是否可以在 tkinter 内的两个按钮之间传输变量!?例如:我想测量按下两个按钮之间的时间并将其打印到标签上......
from tkinter import *
import time
start_time = 0.0
...
def press_start():
start_time = time.time()
def press_end():
estimated_time = time.time() - start_time
lbl_time.config(text=f"Estimated time: {estimated_time }")
...
btn_start = Button(text="Start", command=press_start)
btn_end = Button(text="Start", command=press_end)
lbl_time = Label()
...
【问题讨论】:
-
将
global start_time添加到press_start的开头。