python_细究tkinter——timer

本文最后更新于:1 个月前

注意力集中40min后建议休息一下眼睛,起来喝口水活动一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from pickle import TRUE
import tkinter as tk
import time
from tkinter import messagebox


class App():
def __init__(self,ttext='40 min'):
self.ttext = ttext
self.top = tk.Tk()
self.top.wm_geometry("0x0+100+100")
self.top.overrideredirect(True)
self.root = tk.Toplevel(self.top)
self.root.overrideredirect(True)
print(self.root.overrideredirect(),self.root.state())
# self.root.lift()
self.root.title('Jnarvis')
self.root.wm_geometry("400x428+100+100")
# print(self.root.winfo_height(),self.root.winfo_width(),self.root.winfo_geometry())
self.root.resizable(0,0)
self.label = tk.Label(self.root,text="")
self.label.pack()
self.labe2 = tk.Label(self.root,
text=self.ttext,
font=('Arial',35)
)
self.labe2.pack()
self.btn1 = tk.Button(self.root,text='计时', font=('Arial',20),width=10,height=2,command=self.timing)
self.btn1.pack()
self.btn3 = tk.Button(self.root,text='隐藏', font=('Arial',20),width=10,height=1,command=self.hid)
self.btn3.pack()
self.btn2 = tk.Button(self.root,text='关闭',font=('Arial',20),width=10,height=1,command=self.shutdown)
self.btn2.pack()
self.update_clock()
#self.setimer()
self.root.mainloop()

def update_clock(self):
now = time.strftime("%H:%M:%S")
self.label.configure(
text=now,
font=('Arial',70),)

self.root.after(1000, self.update_clock)

def shutdown(self):

self.top.destroy()

def hid(self):
#self.root.geometry = 0x0+0+0
#self.root.geometry('0x0')
#self.top.state('icon')
if self.root.state() == 'normal':
self.root.overrideredirect(False)
self.root.state('icon')


def timing(self):
print('heo')
jishi = 'Setting: 40 min \n Time is flying, Sir!'
self.labe2.config(
text=jishi,
font=('Arial',35)
)

self.root.after(1000*60*40,self.display)
def display(self):
self.top.destroy()
build()

def zoom(it):
it.state("zoomed")

def build():
appa = App(ttext='Time\'s up \n Have a break, Sir!')
print('hel')
time.sleep(3)
appa.root.lift()
appa.root.attributes('-topmost',True)
appa.root.after_idle(appa.root.attributes,'-topmost',False)
appa.root.after(1, lambda: appa.root.focus_force())

return appa




app=App()

在这里给我留言👇