Amazing-Python-Scripts
85 строк · 1.9 Кб
1import tkinter as tk2import tkinter.font as TkFont3from datetime import datetime4
5
6def timer():7global work8if work:9now = str(txt_var.get())10m, s = map(int, now.split(":"))11m = int(m)12s = int(s)13if (s < 59):14s += 115elif (s == 59):16s = 017if (m < 59):18m += 119elif (m == 59):20m = 021if (m < 10):22m = str(0)+str(m)23else:24m = str(m)25if (s < 10):26s = str(0)+str(s)27else:28s = str(s)29now = m+":"+s30
31txt_var.set(now)32if work:33root.after(1000, timer)34# start function
35
36
37def start():38global work39if not work:40work = True41timer()42
43# stop function
44
45
46def pause():47global work48work = False49
50# reset function
51
52
53def reset():54global work55if not work:56txt_var.set('0:00')57
58
59if __name__ == "__main__":60work = False61
62root = tk.Tk()63root.geometry("500x221") # width x height64root.title("My StopWatch")65
66txt_var = tk.StringVar()67txt_var.set('0:00') # initial display of string68root.config(background="lavender")69
70fontstyle = TkFont.Font(family="Helvetica", size=60,)71tk.Label(root, textvariable=txt_var, font=fontstyle,).pack()72
73# creating the buttons for start,stop and reset74T = tk.Text(root, height=0.7, width=9)75T.pack()76T.insert(tk.END, " mm : ss ")77tk.Button(root, text="Start", command=start,78bg='misty rose').pack(fill='x')79tk.Button(root, text='Pause', command=pause,80bg='misty rose').pack(fill='x')81tk.Button(root, text='Reset', command=reset,82bg='misty rose').pack(fill='x')83tk.Button(root, text='Exit', command=root.destroy,84bg='misty rose').pack(fill='x')85root.mainloop()86