赞
踩
制作了一个可以统计时间管理页面仅供参考
代码如下
- """通过开始时间和结束时间记录所用时间"""
- import tkinter
- from tkinter import *
- from tkinter import messagebox
- import datetime,time
- import math
-
- #open('D:\桌面\python\数据分析\统计信息表.txt','w') #创建一个txt文件
- write = '时间统计表.txt'
- open(write, 'a')
-
- windows = Tk()
- windows.geometry('500x500+500+200')
- windows.title('人员时间统计表')
-
- label2 = Label(windows,text='请输入你的学号(进)')
- label2.place(x=200,y=90)
- entry2 = tkinter.Entry(windows,show='',width=30)
- entry2.place(x=150,y=110)
-
- label1 = Label(windows,text='请输入你的学号(出)')
- label1.place(x=200,y=145)
- entry1 = tkinter.Entry(windows,show='',width=30)
- entry1.place(x=150,y=165)
-
- label3 = Label(windows,text='你的开始时间为:')
- label3.place(x=50,y=210)
-
- label3_1 = Label(windows)
- label3_1.place(x=250,y=210)
-
- label4 = Label(windows,text='你总共时间为:')
- label4.place(x=50,y=320)
-
- label4_1 = Label(windows)
- label4_1.place(x=250,y=320)
-
- #def clear_box(): #定义一个清除的函数
- #entry1.delete("0","end")
- #entry2.delete("0","end")
- #entry3.delete("0","end")
- #entry4.delete("0","end")
-
-
- def time_star_write(): #定义写入文本函数
- file2 = entry2.get()
- if len(file2) != 10:
- return None
- else:
- b = str(file2)
- c = str(time.strftime("%H:%M:%S"))
- with open(write, 'a') as f:
- f.write(b)
- f.write(' ')
- f.write(c)
- f.write('\n')
- # 删除在输入框的内容
- entry2.delete("0", "end")
-
-
- def read_time():
- with open(write,'r+') as f:
- a=f.read()
- file1=entry1.get()
- if str(file1) == a[0:10]:
- b=a[13:21]
- a1=button_star_time.insert('insert',b)
- t=time.strftime("%H:%M:%S")
- t1=int(t[0:2])-int(b[0:2])
- t2=int(math.sqrt((int(t[3:5])-int(b[3:5]))**2))
- t3=int(math.sqrt((int(t[6:8])-int(b[6:8]))**2))
- tt=button_num_time.insert('insert',t1)
- tt1=button_num_time.insert('insert','时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
-
- elif str(file1) == a[0:10] and str(file1) == a[22:32]:
- b=a[35:43]
- a1 = button_star_time.insert('insert',b)
- t = time.strftime("%H:%M:%S")
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
-
- elif str(file1) == a[22:32]:
- b=a[35:43]
- a1 = button_star_time.insert('insert',b)
- t = time.strftime("%H:%M:%S")
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- elif str(file1) == a[44:54]:
- b=a[57:65]
- a1 = button_star_time.insert('insert',b)
- t = time.strftime("%H:%M:%S")
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- elif str(file1) == a[66:76]:
- b = a[79:87]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- else:
- return None
-
-
- def read_times(): #定义读取写入的数据
- with open(write, 'r+') as f:
- a = f.read()
- file1 = entry1.get()
- x1 = 0
- y1 = 10
- x2 = 13
- y2 = 21
-
- if str(file1) == a[x1 + 22 * 10:y1 + 22 * 10]:
- b = a[x2 + 22 * 10:y2 + 22 * 10]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 9:y1 + 22 * 9]:
- b = a[x2 + 22 * 9:y2 + 22 * 9]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 8:y1 + 22 * 8]:
- b = a[x2 + 22 * 8:y2 + 22 * 8]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 7:y1 + 22 * 7]:
- b = a[x2 + 22 * 7:y2 + 22 * 7]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 6:y1 + 22 * 6]:
- b = a[x2 + 22 * 6:y2 + 22 * 6]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 5:y1 + 22 * 5]:
- b = a[x2 + 22 * 5:y2 + 22 * 5]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 4:y1 + 22 * 4]:
- b = a[x2 + 22 * 4:y2 + 22 * 4]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 3:y1 + 22 * 3]:
- b = a[x2 + 22 * 3:y2 + 22 * 3]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 2:y1 + 22 * 2]:
- b = a[x2 + 22 * 2:y2 + 22 * 2]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1 + 22 * 1:y1 + 22 * 1]:
- b = a[x2 + 22 * 1:y2 + 22 * 1]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
-
- elif str(file1) == a[x1:y1]:
- b = a[x2:y2]
- a1 = button_star_time.insert('insert', b)
- t = time.strftime("%H:%M:%S")
- try:
- t1 = int(t[0:2]) - int(b[0:2])
- t2 = int(math.sqrt((int(t[3:5]) - int(b[3:5])) ** 2))
- t3 = int(math.sqrt((int(t[6:8]) - int(b[6:8])) ** 2))
- except ValueError:
- pass
-
- try:
- tt = button_num_time.insert('insert', t1)
- tt1 = button_num_time.insert('insert', '时')
- tt2 = button_num_time.insert('insert', t2)
- tt3 = button_num_time.insert('insert', '分')
- tt4 = button_num_time.insert('insert', t3)
- tt5 = button_num_time.insert('insert', '秒')
- except UnboundLocalError:
- pass
- else:
- return None
-
-
- def inserts_text():
- var1 = b.get()
- a1 = t1.insert('insert', var1)
-
-
- def clearn(): #定义清除数据函数
- entry1.delete("0", "end")
- button_star_time.delete(1.0,9999999999999999.0)
- button_num_time.delete(1.0,999999.0)
-
-
- button_close_sex=Button(windows,text='确定',height=0,width=10,command=time_star_write)
- button_close_sex.place(x=360,y=105)
-
- button_close=Button(windows,text='确定',height=0,width=10,command=read_times)
- button_close.place(x=360,y=160)
-
- button_clearn=Button(windows,text='清除',height=0,width=10,command=clearn)
- button_clearn.place(x=360,y=205)
-
- button_star_time=tkinter.Text(windows,height=1,width=30)
- button_star_time.place(x=150,y=210)
-
- button_num_time=tkinter.Text(windows,height=1,width=30)
- button_num_time.place(x=150,y=325)
-
- windows.mainloop() #显示窗口
-
- with open(write,'r+') as f: #定时清理数据
- while True:
- time_now=time.strftime("%H:%M:%S")
- for i in range(1,12):
- if int(time_now[0:2]) == i:
- continue
- elif int(time_now[0:2]) == 12:
- f.truncate(0)
- break
-
-
-
事例如下
当文件第一次运行时会在目录页产生一个txt文件用于存储数据,当再次输入学号就会返回你所用的时间统计人数上限可自行增加。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。