当前位置:   article > 正文

时间统计窗口系统_统计时间窗口

统计时间窗口

 制作了一个可以统计时间管理页面仅供参考

 代码如下

  1. """通过开始时间和结束时间记录所用时间"""
  2. import tkinter
  3. from tkinter import *
  4. from tkinter import messagebox
  5. import datetime,time
  6. import math
  7. #open('D:\桌面\python\数据分析\统计信息表.txt','w') #创建一个txt文件
  8. write = '时间统计表.txt'
  9. open(write, 'a')
  10. windows = Tk()
  11. windows.geometry('500x500+500+200')
  12. windows.title('人员时间统计表')
  13. label2 = Label(windows,text='请输入你的学号(进)')
  14. label2.place(x=200,y=90)
  15. entry2 = tkinter.Entry(windows,show='',width=30)
  16. entry2.place(x=150,y=110)
  17. label1 = Label(windows,text='请输入你的学号(出)')
  18. label1.place(x=200,y=145)
  19. entry1 = tkinter.Entry(windows,show='',width=30)
  20. entry1.place(x=150,y=165)
  21. label3 = Label(windows,text='你的开始时间为:')
  22. label3.place(x=50,y=210)
  23. label3_1 = Label(windows)
  24. label3_1.place(x=250,y=210)
  25. label4 = Label(windows,text='你总共时间为:')
  26. label4.place(x=50,y=320)
  27. label4_1 = Label(windows)
  28. label4_1.place(x=250,y=320)
  29. #def clear_box(): #定义一个清除的函数
  30. #entry1.delete("0","end")
  31. #entry2.delete("0","end")
  32. #entry3.delete("0","end")
  33. #entry4.delete("0","end")
  34. def time_star_write(): #定义写入文本函数
  35. file2 = entry2.get()
  36. if len(file2) != 10:
  37. return None
  38. else:
  39. b = str(file2)
  40. c = str(time.strftime("%H:%M:%S"))
  41. with open(write, 'a') as f:
  42. f.write(b)
  43. f.write(' ')
  44. f.write(c)
  45. f.write('\n')
  46. # 删除在输入框的内容
  47. entry2.delete("0", "end")
  48. def read_time():
  49. with open(write,'r+') as f:
  50. a=f.read()
  51. file1=entry1.get()
  52. if str(file1) == a[0:10]:
  53. b=a[13:21]
  54. a1=button_star_time.insert('insert',b)
  55. t=time.strftime("%H:%M:%S")
  56. t1=int(t[0:2])-int(b[0:2])
  57. t2=int(math.sqrt((int(t[3:5])-int(b[3:5]))**2))
  58. t3=int(math.sqrt((int(t[6:8])-int(b[6:8]))**2))
  59. tt=button_num_time.insert('insert',t1)
  60. tt1=button_num_time.insert('insert','时')
  61. tt2 = button_num_time.insert('insert', t2)
  62. tt3 = button_num_time.insert('insert', '分')
  63. tt4 = button_num_time.insert('insert', t3)
  64. tt5 = button_num_time.insert('insert', '秒')
  65. elif str(file1) == a[0:10] and str(file1) == a[22:32]:
  66. b=a[35:43]
  67. a1 = button_star_time.insert('insert',b)
  68. t = time.strftime("%H:%M:%S")
  69. t1 = int(t[0:2]) - int(b[0:2])
  70. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  71. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  72. tt = button_num_time.insert('insert', t1)
  73. tt1 = button_num_time.insert('insert', '时')
  74. tt2 = button_num_time.insert('insert', t2)
  75. tt3 = button_num_time.insert('insert', '分')
  76. tt4 = button_num_time.insert('insert', t3)
  77. tt5 = button_num_time.insert('insert', '秒')
  78. elif str(file1) == a[22:32]:
  79. b=a[35:43]
  80. a1 = button_star_time.insert('insert',b)
  81. t = time.strftime("%H:%M:%S")
  82. t1 = int(t[0:2]) - int(b[0:2])
  83. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  84. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  85. tt = button_num_time.insert('insert', t1)
  86. tt1 = button_num_time.insert('insert', '时')
  87. tt2 = button_num_time.insert('insert', t2)
  88. tt3 = button_num_time.insert('insert', '分')
  89. tt4 = button_num_time.insert('insert', t3)
  90. tt5 = button_num_time.insert('insert', '秒')
  91. elif str(file1) == a[44:54]:
  92. b=a[57:65]
  93. a1 = button_star_time.insert('insert',b)
  94. t = time.strftime("%H:%M:%S")
  95. t1 = int(t[0:2]) - int(b[0:2])
  96. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  97. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  98. tt = button_num_time.insert('insert', t1)
  99. tt1 = button_num_time.insert('insert', '时')
  100. tt2 = button_num_time.insert('insert', t2)
  101. tt3 = button_num_time.insert('insert', '分')
  102. tt4 = button_num_time.insert('insert', t3)
  103. tt5 = button_num_time.insert('insert', '秒')
  104. elif str(file1) == a[66:76]:
  105. b = a[79:87]
  106. a1 = button_star_time.insert('insert', b)
  107. t = time.strftime("%H:%M:%S")
  108. t1 = int(t[0:2]) - int(b[0:2])
  109. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  110. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  111. tt = button_num_time.insert('insert', t1)
  112. tt1 = button_num_time.insert('insert', '时')
  113. tt2 = button_num_time.insert('insert', t2)
  114. tt3 = button_num_time.insert('insert', '分')
  115. tt4 = button_num_time.insert('insert', t3)
  116. tt5 = button_num_time.insert('insert', '秒')
  117. else:
  118. return None
  119. def read_times(): #定义读取写入的数据
  120. with open(write, 'r+') as f:
  121. a = f.read()
  122. file1 = entry1.get()
  123. x1 = 0
  124. y1 = 10
  125. x2 = 13
  126. y2 = 21
  127. if str(file1) == a[x1 + 22 * 10:y1 + 22 * 10]:
  128. b = a[x2 + 22 * 10:y2 + 22 * 10]
  129. a1 = button_star_time.insert('insert', b)
  130. t = time.strftime("%H:%M:%S")
  131. try:
  132. t1 = int(t[0:2]) - int(b[0:2])
  133. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  134. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  135. except ValueError:
  136. pass
  137. try:
  138. tt = button_num_time.insert('insert', t1)
  139. tt1 = button_num_time.insert('insert', '时')
  140. tt2 = button_num_time.insert('insert', t2)
  141. tt3 = button_num_time.insert('insert', '分')
  142. tt4 = button_num_time.insert('insert', t3)
  143. tt5 = button_num_time.insert('insert', '秒')
  144. except UnboundLocalError:
  145. pass
  146. elif str(file1) == a[x1 + 22 * 9:y1 + 22 * 9]:
  147. b = a[x2 + 22 * 9:y2 + 22 * 9]
  148. a1 = button_star_time.insert('insert', b)
  149. t = time.strftime("%H:%M:%S")
  150. try:
  151. t1 = int(t[0:2]) - int(b[0:2])
  152. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  153. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  154. except ValueError:
  155. pass
  156. try:
  157. tt = button_num_time.insert('insert', t1)
  158. tt1 = button_num_time.insert('insert', '时')
  159. tt2 = button_num_time.insert('insert', t2)
  160. tt3 = button_num_time.insert('insert', '分')
  161. tt4 = button_num_time.insert('insert', t3)
  162. tt5 = button_num_time.insert('insert', '秒')
  163. except UnboundLocalError:
  164. pass
  165. elif str(file1) == a[x1 + 22 * 8:y1 + 22 * 8]:
  166. b = a[x2 + 22 * 8:y2 + 22 * 8]
  167. a1 = button_star_time.insert('insert', b)
  168. t = time.strftime("%H:%M:%S")
  169. try:
  170. t1 = int(t[0:2]) - int(b[0:2])
  171. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  172. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  173. except ValueError:
  174. pass
  175. try:
  176. tt = button_num_time.insert('insert', t1)
  177. tt1 = button_num_time.insert('insert', '时')
  178. tt2 = button_num_time.insert('insert', t2)
  179. tt3 = button_num_time.insert('insert', '分')
  180. tt4 = button_num_time.insert('insert', t3)
  181. tt5 = button_num_time.insert('insert', '秒')
  182. except UnboundLocalError:
  183. pass
  184. elif str(file1) == a[x1 + 22 * 7:y1 + 22 * 7]:
  185. b = a[x2 + 22 * 7:y2 + 22 * 7]
  186. a1 = button_star_time.insert('insert', b)
  187. t = time.strftime("%H:%M:%S")
  188. try:
  189. t1 = int(t[0:2]) - int(b[0:2])
  190. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  191. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  192. except ValueError:
  193. pass
  194. try:
  195. tt = button_num_time.insert('insert', t1)
  196. tt1 = button_num_time.insert('insert', '时')
  197. tt2 = button_num_time.insert('insert', t2)
  198. tt3 = button_num_time.insert('insert', '分')
  199. tt4 = button_num_time.insert('insert', t3)
  200. tt5 = button_num_time.insert('insert', '秒')
  201. except UnboundLocalError:
  202. pass
  203. elif str(file1) == a[x1 + 22 * 6:y1 + 22 * 6]:
  204. b = a[x2 + 22 * 6:y2 + 22 * 6]
  205. a1 = button_star_time.insert('insert', b)
  206. t = time.strftime("%H:%M:%S")
  207. try:
  208. t1 = int(t[0:2]) - int(b[0:2])
  209. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  210. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  211. except ValueError:
  212. pass
  213. try:
  214. tt = button_num_time.insert('insert', t1)
  215. tt1 = button_num_time.insert('insert', '时')
  216. tt2 = button_num_time.insert('insert', t2)
  217. tt3 = button_num_time.insert('insert', '分')
  218. tt4 = button_num_time.insert('insert', t3)
  219. tt5 = button_num_time.insert('insert', '秒')
  220. except UnboundLocalError:
  221. pass
  222. elif str(file1) == a[x1 + 22 * 5:y1 + 22 * 5]:
  223. b = a[x2 + 22 * 5:y2 + 22 * 5]
  224. a1 = button_star_time.insert('insert', b)
  225. t = time.strftime("%H:%M:%S")
  226. try:
  227. t1 = int(t[0:2]) - int(b[0:2])
  228. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  229. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  230. except ValueError:
  231. pass
  232. try:
  233. tt = button_num_time.insert('insert', t1)
  234. tt1 = button_num_time.insert('insert', '时')
  235. tt2 = button_num_time.insert('insert', t2)
  236. tt3 = button_num_time.insert('insert', '分')
  237. tt4 = button_num_time.insert('insert', t3)
  238. tt5 = button_num_time.insert('insert', '秒')
  239. except UnboundLocalError:
  240. pass
  241. elif str(file1) == a[x1 + 22 * 4:y1 + 22 * 4]:
  242. b = a[x2 + 22 * 4:y2 + 22 * 4]
  243. a1 = button_star_time.insert('insert', b)
  244. t = time.strftime("%H:%M:%S")
  245. try:
  246. t1 = int(t[0:2]) - int(b[0:2])
  247. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  248. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  249. except ValueError:
  250. pass
  251. try:
  252. tt = button_num_time.insert('insert', t1)
  253. tt1 = button_num_time.insert('insert', '时')
  254. tt2 = button_num_time.insert('insert', t2)
  255. tt3 = button_num_time.insert('insert', '分')
  256. tt4 = button_num_time.insert('insert', t3)
  257. tt5 = button_num_time.insert('insert', '秒')
  258. except UnboundLocalError:
  259. pass
  260. elif str(file1) == a[x1 + 22 * 3:y1 + 22 * 3]:
  261. b = a[x2 + 22 * 3:y2 + 22 * 3]
  262. a1 = button_star_time.insert('insert', b)
  263. t = time.strftime("%H:%M:%S")
  264. try:
  265. t1 = int(t[0:2]) - int(b[0:2])
  266. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  267. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  268. except ValueError:
  269. pass
  270. try:
  271. tt = button_num_time.insert('insert', t1)
  272. tt1 = button_num_time.insert('insert', '时')
  273. tt2 = button_num_time.insert('insert', t2)
  274. tt3 = button_num_time.insert('insert', '分')
  275. tt4 = button_num_time.insert('insert', t3)
  276. tt5 = button_num_time.insert('insert', '秒')
  277. except UnboundLocalError:
  278. pass
  279. elif str(file1) == a[x1 + 22 * 2:y1 + 22 * 2]:
  280. b = a[x2 + 22 * 2:y2 + 22 * 2]
  281. a1 = button_star_time.insert('insert', b)
  282. t = time.strftime("%H:%M:%S")
  283. try:
  284. t1 = int(t[0:2]) - int(b[0:2])
  285. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  286. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  287. except ValueError:
  288. pass
  289. try:
  290. tt = button_num_time.insert('insert', t1)
  291. tt1 = button_num_time.insert('insert', '时')
  292. tt2 = button_num_time.insert('insert', t2)
  293. tt3 = button_num_time.insert('insert', '分')
  294. tt4 = button_num_time.insert('insert', t3)
  295. tt5 = button_num_time.insert('insert', '秒')
  296. except UnboundLocalError:
  297. pass
  298. elif str(file1) == a[x1 + 22 * 1:y1 + 22 * 1]:
  299. b = a[x2 + 22 * 1:y2 + 22 * 1]
  300. a1 = button_star_time.insert('insert', b)
  301. t = time.strftime("%H:%M:%S")
  302. try:
  303. t1 = int(t[0:2]) - int(b[0:2])
  304. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  305. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  306. except ValueError:
  307. pass
  308. try:
  309. tt = button_num_time.insert('insert', t1)
  310. tt1 = button_num_time.insert('insert', '时')
  311. tt2 = button_num_time.insert('insert', t2)
  312. tt3 = button_num_time.insert('insert', '分')
  313. tt4 = button_num_time.insert('insert', t3)
  314. tt5 = button_num_time.insert('insert', '秒')
  315. except UnboundLocalError:
  316. pass
  317. elif str(file1) == a[x1:y1]:
  318. b = a[x2:y2]
  319. a1 = button_star_time.insert('insert', b)
  320. t = time.strftime("%H:%M:%S")
  321. try:
  322. t1 = int(t[0:2]) - int(b[0:2])
  323. t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
  324. t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
  325. except ValueError:
  326. pass
  327. try:
  328. tt = button_num_time.insert('insert', t1)
  329. tt1 = button_num_time.insert('insert', '时')
  330. tt2 = button_num_time.insert('insert', t2)
  331. tt3 = button_num_time.insert('insert', '分')
  332. tt4 = button_num_time.insert('insert', t3)
  333. tt5 = button_num_time.insert('insert', '秒')
  334. except UnboundLocalError:
  335. pass
  336. else:
  337. return None
  338. def inserts_text():
  339. var1 = b.get()
  340. a1 = t1.insert('insert', var1)
  341. def clearn(): #定义清除数据函数
  342. entry1.delete("0", "end")
  343. button_star_time.delete(1.0,9999999999999999.0)
  344. button_num_time.delete(1.0,999999.0)
  345. button_close_sex=Button(windows,text='确定',height=0,width=10,command=time_star_write)
  346. button_close_sex.place(x=360,y=105)
  347. button_close=Button(windows,text='确定',height=0,width=10,command=read_times)
  348. button_close.place(x=360,y=160)
  349. button_clearn=Button(windows,text='清除',height=0,width=10,command=clearn)
  350. button_clearn.place(x=360,y=205)
  351. button_star_time=tkinter.Text(windows,height=1,width=30)
  352. button_star_time.place(x=150,y=210)
  353. button_num_time=tkinter.Text(windows,height=1,width=30)
  354. button_num_time.place(x=150,y=325)
  355. windows.mainloop() #显示窗口
  356. with open(write,'r+') as f: #定时清理数据
  357. while True:
  358. time_now=time.strftime("%H:%M:%S")
  359. for i in range(1,12):
  360. if int(time_now[0:2]) == i:
  361. continue
  362. elif int(time_now[0:2]) == 12:
  363. f.truncate(0)
  364. break

事例如下

 当文件第一次运行时会在目录页产生一个txt文件用于存储数据,当再次输入学号就会返回你所用的时间统计人数上限可自行增加。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/544073
推荐阅读
相关标签
  

闽ICP备14008679号