The Python timer has many problems during running. Let's take a look at how to solve these problems. I hope you will have some gains. The Code is as follows:
- #! /Usr/bin/ENV Python
- Import datetime
- Import sys
- Import threading
- From tkinter import *
- Minute = 60 * int (SYS. argv [1])
- Curtime = datetime. datetime. Now ()
- Print ("time:", curtime)
- Scrtime = curtime + datetime. timedelta (0, minute, 0)
- Print ("target time:", scrtime)
- Def wait ():
- Threading. _ sleep (minute)
- Def Stat ():
- Dsttime = datetime. datetime. Now ()
- TMP = dsttime-scrtime + scrtime
- Print ("current time:", TMP)
- If TMP = dsttime:
- Class app (FRAME ):
- Def _ init _ (self, Master = none ):
- Frame. _ init _ (self, Master)
- Self. Pack ()
- MyApp = app ()
- MyApp. master. Title ("time reached ")
- MyApp. master. maxsize (150,0)
- MyApp. mainloop ()
- Else:
- Print ("no ")
- Wait ()
- Stat ()
The above describes how to use the python timer.