Source file
01 import tkinter 02 import time 03 04 star=time.time() 05 06 def gettime(): 07 elap=time.time()-star# 获取时间差 08 hours=int(elap/3600) 09 minutes = int((elap-hours*3600)/60) 10 seconds The = int ( ELAP - minutes * 60.0 - hours * 3600 ) . 11 var . SET ( ' % 0 2D: % 0 2D: % 0 2D' % ( hours , minutes , seconds The )) 12 is the root . After ( 1000 , getTime ) # call the function itself every 1s acquisition time 13 is 14 the root = Tkinter . Tk () 15the root . title ( 'test timer' ) 16 the root . Geometry ( '1000x400' ) . 17 var = Tkinter . StringVar () 18 is Tkinter . the Label ( the root , text = 'examination timing' , font = 'Bold Black 50' ). Pack ( Side = 'Top' ); . 19 LB = Tkinter . the Label ( the root , textvariable= Var , FG = 'Red' , font = ( "Microsoft elegant black" , 150 )) # set the font size of the color 20 is LB . Pack ( Side = 'Top' ) 21 is #quit button to exit; the Run button to print the results 22 is Tkinter . the Button ( the root , text = 'exit' , Command = the root . quit ). Pack ( Side = 'left' ) 23 is Tkinter . the Button(root, text='运行', command=gettime).pack(side='right') 24 root.mainloop()