from tkinter import *
root=Tk()
root.title("倒计时")
root.geometry("240x120")
running=False
paused=False
r_time=60
def update_timer():
global running,paused,r_time
if running:
if paused:
label1.config(text="暂停")
else:
if r_time>0:
r_time-=1
label1.config(text=str(r_time))
root.after(1000,update_timer)
else:
running=False
label1.config(text="时间到!")
def start():
global running
if not running:
running = True
update_timer()
def pause():
global running
global paused
if running and not paused:
paused = True
def resume():
global paused
if paused:
paused = False
update_timer()
label1=Label(root,font=("Arial",40,"bold"),bg="yellow",fg="blue",width=8,anchor="center")
label1.grid(row=0,rowspan=3)
start_button=Button(root,text="开始",command=start)
start_button.place(x=40,y=70)
pause_button=Button(root,text="暂停",command=pause)
pause_button.place(x=80,y=70)
resume_button=Button(root,text="恢复",command=resume)
resume_button.place(x=120,y=70)
releas_button=Button(root,text="关闭",command=root.destroy)
releas_button.place(x=160,y=70)
root.mainloop()