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.