what/随机选人-tk - 作业版-s.py
2023-10-25 21:33:05 +08:00

1225 lines
55 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''
亲爱的syj
你可能在这里看到一些匪夷所思的代码,因为有些已经没用的功能,还没来得及删。
bugs
“设置”是新加的内容,但问题很多,你可以试试。
“倒计时”的结束时间必须在今天,如果结束时间是第二天会立刻停止,知道原因,但没来得及改。
“查看并复制”如果一项作业太长就会显示不全也知道原因但懒得改毕竟可以看word
“查看word”时如果这个文档正在使用就会卡白屏能改但还没改。
***“屏蔽任务管理器”模块不知什么原因在Windows 7上不起作用但Windows 11可以。马上期中了希望火速把这问题改了要不然就会有一堆人把我程序一关然后用钉钉查我成绩***
虽然bug一堆但我打算先把留作业的模块的按钮中的文字用标志代替已经把“确定并保存”按钮改成了标志但改圆角时失败了。
移除ttkbootstrap虽然能变成圆角但太丑了所以后来又把ttkbootstrap请回来了。
'''
'''
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* . ' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
*
* .............................................
* 万分感谢
'''
from threading import Thread
from tkinter import *
from arcade import load_sound,play_sound,stop_sound
import random,tkinter,time,xlrd,datetime,logging,hashlib,os,shutil,pygetwindow,pyperclip
from ttkbootstrap import Style
from tkinter import ttk
from docx import Document
from tkinter import messagebox
from PIL import Image, ImageTk, ImageDraw
def check_pwd(pwd):
global password
password=False
try:
with open('support/config.ini') as v:
for x in v.readlines():
if 'pwd:' in x:
break
except:
on_button_click('没有找到密码文件','')
pwd='pwd:'+pwd
if pwd==x:
password=True
return True
else:
on_button_click('请检查密码','')
return False
def loading():
global fin,a,root,screen_width,ll,back,back_photo,up_photo,down_photo,stop_photo,star,star_photo,bigback_photo,paus_photo,cross_photo,speed,save_and_continue_photo,continued_photo
fin=False
style = Style(theme='cosmo')
root = style.master
draggable_window = DraggableWindow(root)
content_frame = ttk.Frame(root)
screen_width = root.winfo_screenwidth()
root.resizable(0, 0)
root.overrideredirect(1)
back = Image.open("support/back.png")
smallback = back.resize((30, 30))
back_photo = ImageTk.PhotoImage(smallback)
bigback = Image.open("support/bigback.png")
bigback= bigback.resize((40, 40))
bigback_photo=ImageTk.PhotoImage(bigback)
up = Image.open("support/up.png")
up = up.resize((40, 40))
up_photo = ImageTk.PhotoImage(up)
down = Image.open("support/down.png")
down = down.resize((40, 40))
down_photo = ImageTk.PhotoImage(down)
stop = Image.open("support/stop.png")
stop = stop.resize((40, 40))
stop_photo = ImageTk.PhotoImage(stop)
star = Image.open("support/star.png")
star = star.resize((40, 40))
star_photo = ImageTk.PhotoImage(star)
paus = Image.open("support/paus.png")
paus = paus.resize((40, 40))
paus_photo = ImageTk.PhotoImage(paus)
cross = Image.open("support/cross.png")
cross = cross.resize((20, 20))
cross_photo = ImageTk.PhotoImage(cross)
save_and_continue = Image.open("support/save_and_continue.png")
save_and_continue = save_and_continue.resize((80, 40))
save_and_continue_photo = ImageTk.PhotoImage(save_and_continue)
continued = Image.open("support/continue.png")
continued = continued.resize((20, 20))
continued_photo = ImageTk.PhotoImage(continued)
for x in range(75):
win_width = (4*x)+201
win_height = (4*x)+1
win_x = root.winfo_screenwidth() // 2 - win_width // 2
win_y = root.winfo_screenheight() // 2 - win_height // 2
root.geometry('{}x{}+{}+{}'.format(win_width, win_height, win_x, win_y))
root.update()
log('正在清理文件','info')
while fin==False:
c = tkinter.Label(text=ll, font=('宋体'))
c.place(relx=0.5, rely=0.8, anchor='center')
time.sleep(0.08)
root.update_idletasks()
root.update()
c.destroy()
else:
try:
c.destroy()
except:
pass
k = tkinter.Label(text='本次共清理了\n' + str(a) + '个文件', font=('宋体', 48))
log('本次共清理了' + str(a) + '个文件','info')
k.place(relx=0.5, rely=0.5, anchor='center')
root.after(3000, lambda: schedule('fromclean'))
root.mainloop()
def log(content,rate):
if rate=='info':
logging.info(content)
elif rate=='warning':
logging.warning(content)
elif rate=='error':
logging.error(content)
with open('support/config.ini','a+') as f:
a=f.readlines()
for x in range(len(a)):
if '日志处理后sha256' in a[x]:
del f.readlines()[x]
f.write('日志处理后sha256:'+file_sha256(r'support/journal.log'))
def on_button_click(content,pppp):
wait_window = tkinter.Toplevel(root)
wait_window.wm_attributes('-topmost', 1)
win_width = 400
win_height = 300
wait_window.overrideredirect(1)
win_x = screen_width - win_width
win_y = wait_window.winfo_screenheight() // 2 - win_height // 2
wait_window.geometry('{}x{}+{}+{}'.format(win_width, win_height, win_x, win_y))
p = tkinter.Label(wait_window, text=content, font=('仿宋', 24), justify='left')
p.place(rely=0.1, relx=0.5, anchor='n')
pp = tkinter.Button(wait_window, text="确定", command=wait_window.destroy, font=('宋体', 24))
pp.place(rely=0.8, relx=0.3, anchor='center')
if pppp=='pppp':
ppp = tkinter.Entry(wait_window, width=30,show='*')
ppp.place(relx=0.5, rely=0.6, anchor='center')
pppp=tkinter.Button(wait_window,text='忽略',command=lambda:check_pwd(ppp.get()) and wait_window.destroy(),font=('宋体', 24))
pppp.place(relx=0.6,rely=0.8,anchor='center')
wait_window.wait_window()
return True
class DraggableWindow:
def __init__(self, root):
self.root = root
self.root.bind("<ButtonPress-1>", self.start_move)
self.root.bind("<ButtonRelease-1>", self.stop_move)
self.root.bind("<B1-Motion>", self.on_move)
self.draggable = False
self.offset = {"x": 0, "y": 0}
def start_move(self, event):
if isinstance(event.widget, tkinter.Button) or isinstance(event.widget, tkinter.Text):
return
self.draggable = True
self.offset["x"] = event.x
self.offset["y"] = event.y
def stop_move(self, event):
self.draggable = False
def on_move(self, event):
if isinstance(event.widget, tkinter.Button) or isinstance(event.widget, tkinter.Text) or isinstance(event.widget, tkinter.Entry):
return
if self.draggable:
x = self.root.winfo_x() + (event.x - self.offset["x"])
y = self.root.winfo_y() + (event.y - self.offset["y"])
self.root.geometry(f"+{x}+{y}")
photo=None
info=''
canceltopping=False
d = datetime.datetime.now()
chosed=[]
zhou=['周一','周二','周三','周四','周五','周六','周日']
shouldnot=[]
logging.basicConfig(filename="support/journal.log", filemode="a+", format="%(asctime)s %(name)s:%(levelname)s:%(message)s", datefmt='', level=logging.DEBUG)
def file_hash(file_path: str, hash_method) -> str:
h = hash_method()
with open(file_path, 'rb') as f:
while True:
b = f.read(8192)
if not b:
break
h.update(b)
f.close()
return h.hexdigest()
def file_sha256(file_path: str) -> str:
return file_hash(file_path, hashlib.sha256)
def check_class():
global zhou,d
try:
excel = xlrd.open_workbook("support/时刻表.xls")
sheet = excel.sheet_by_index(0)
rows: list = sheet.row_values(0)
index = rows.index('时刻表')
listindes = sheet.col_values(index)
for x in range(1, len(listindes)):
a = listindes[x].split('-')
start_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[0], '%Y-%m-%d%H:%M')
end_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[1], '%Y-%m-%d%H:%M')
now_time = datetime.datetime.now()
if start_time < now_time < end_time:
excel = xlrd.open_workbook("support/课程表.xls")
sheet = excel.sheet_by_index(0)
rows: list = sheet.row_values(0)
index = rows.index(zhou[d.weekday()])
listindes = sheet.col_values(index)
return listindes[x]
return False
except:
return False
def rest():
try:
excel = xlrd.open_workbook("support/时间表.xls")
sheet = excel.sheet_by_index(0)
rows: list = sheet.row_values(0)
index = rows.index('时间表')
listindes = sheet.col_values(index)
for x in range(1, len(listindes)):
a = listindes[x].split('-')
start_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[0], '%Y-%m-%d%H:%M')
end_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[1], '%Y-%m-%d%H:%M')
now_time = datetime.datetime.now()
if start_time < now_time < end_time:
return True
return False
except:
return False
def verify_pwd():
global password
wait_window = tkinter.Toplevel(root)
win_width = 400
win_height = 300
wait_window.overrideredirect(1)
win_x = screen_width - win_width
win_y = wait_window.winfo_screenheight() // 2 - win_height // 2
wait_window.geometry('{}x{}+{}+{}'.format(win_width, win_height, win_x, win_y))
p = tkinter.Label(wait_window, text="验证密码\n成功后可打开任务管理器", font=('仿宋', 24), justify='left')
p.place(rely=0.1, relx=0.5, anchor='n')
pp = tkinter.Button(wait_window, text="取消", command=wait_window.destroy, font=('宋体', 24))
pp.place(rely=0.8, relx=0.3, anchor='center')
ppp = tkinter.Entry(wait_window, width=30, show='*')
ppp.place(relx=0.5, rely=0.6, anchor='center')
pppp = tkinter.Button(wait_window, text='验证', command=lambda: check_pwd(ppp.get()) and wait_window.destroy(),
font=('宋体', 24))
pppp.place(relx=0.6, rely=0.8, anchor='center')
wait_window.wait_window()
if password==True:
with open('support/temp','w+') as f:
f.write('True')
password=False
return True
def urge():
global toplevel,pressed_f4
time.sleep(10)
pressed_f4 = False
subj=['语文','数学','英语','物理','化学','政治']
def do_exit():
global pressed_f4
if pressed_f4:
pressed_f4 = False
toplevel.destroy()
def alt_f4(event):
global pressed_f4
pressed_f4 = True
with open('support/info.txt','r+') as f:
for x in f.readlines():
if '晚自习' in x:
break
a = x.split('')
toplevel = tkinter.Toplevel()
toplevel.geometry('{}x{}+{}+{}'.format(screen_width-2, toplevel.winfo_screenheight()-2, 0, 0))
toplevel.resizable(0, 0)
toplevel.overrideredirect(1)
toplevel.wm_attributes('-topmost', 1)
toplevel.protocol("WM_DELETE_WINDOW")
toplevel.bind('<Alt-F4>', alt_f4)
toplevel.protocol("WM_DELETE_WINDOW", do_exit)
toplevel.configure(bg='white')
toplevel.wm_attributes('-transparentcolor', 'white')
flag=True
while flag:
start_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[1], '%Y-%m-%d%H:%M')
now_time = datetime.datetime.now()
while start_time < now_time and flag:
urg = []
subjects = open('support/subjects', 'r').read().splitlines()
for i, subject in enumerate(subjects):
if str(d.date()) + subject in os.listdir('support/homework/') and (not subject in urg):
with open('support/homework/' + str(d.date()) + subject, 'r+') as f:
if f.readlines() != []:
pass
elif subject in subj:
urg.append(subject)
else:
if (not subject in urg) and (subject in subj):
urg.append(subject)
for btn in toplevel.place_slaves():
btn.destroy()
for x in urg:
if z==False:
tkinter.Button(toplevel, text=x + '课代表速留作业', font=('宋体', 30)).place(relx=random.uniform(0, 1),
rely=random.uniform(0, 1))
if urg==[]:
flag=False
toplevel.update()
time.sleep(1)
else:
delta = start_time - now_time
seconds = delta.total_seconds()
time.sleep(seconds)
z=False
def countdown():
global speed
for btn in root.place_slaves():
btn.destroy()
def returnforpaused(whattime):
current_time = datetime.datetime.now().time()
current_datetime = datetime.datetime.combine(datetime.date.today(), current_time)
future_datetime = current_datetime + whattime
future_time = future_datetime.time().replace(microsecond=0)
return future_time
def paused(whattime):
global flag,star_photo
flag = False
pause = tkinter.Button(image=star_photo, command=lambda: updated(returnforpaused(whattime)), font=('宋体', 30))
pause.grid(column=0, row=3, sticky='nsew')
def updated(future_time):
global starttime, flag,bigback_photo,stop_photo,paus_photo
flag = True
for child in root.grid_slaves():
child.grid_remove()
time1 = datetime.time(int(str(future_time).split(':')[0]), int(str(future_time).split(':')[1]),
int(str(future_time).split(':')[2]))
datetime1 = datetime.datetime.combine(datetime.date.today(), time1)
current_time = datetime.datetime.now().time()
pause = tkinter.Button(image=paus_photo, command=lambda: paused(
datetime1 - datetime.datetime.combine(datetime.date.today(), current_time).replace(microsecond=0)),
font=('宋体', 30))
pause.grid(column=0, row=3, sticky='nsew')
cancel = tkinter.Button(image=stop_photo,command=lambda: welcome(), font=('宋体', 30))
cancel.grid(column=1, row=3, sticky='nsew')
back = tkinter.Button(image=bigback_photo,command=lambda: schedule('fromclean'), font=('宋体', 30),height=60)
back.grid(column=2, row=3, sticky='nsew')
while flag == True and datetime.datetime.now().time() <= (
datetime.time(int(str(future_time).split(':')[0]), int(str(future_time).split(':')[1]),
int(str(future_time).split(':')[2]))):
current_time = datetime.datetime.now().time()
datetime2 = datetime.datetime.combine(datetime.date.today(), current_time)
time_difference = datetime1 - datetime2
hours = time_difference.seconds // 3600
minutes = (time_difference.seconds % 3600) // 60
seconds = time_difference.seconds % 60
tkinter.Label(text=str(hours).zfill(2), font=('宋体', 50)).grid(column=0, row=1, sticky='nsew')
tkinter.Label(text=str(minutes).zfill(2), font=('宋体', 50)).grid(column=1, row=1, sticky='nsew')
tkinter.Label(text=str(seconds).zfill(2), font=('宋体', 50)).grid(column=2, row=1, sticky='nsew')
root.update()
time.sleep(1)
else:
if flag == False:
pass
else:
finishing()
def finishing():
global bigback_photo
for child in root.grid_slaves():
child.grid_remove()
tkinter.Label(text='时间到了', font=('华文行楷', 50)).grid(column=0, columnspan=3, row=1, sticky='nsew')
cancel = tkinter.Button(text='确定', command=lambda: stop_sound(player) | welcome(), font=('宋体', 30))
cancel.grid(column=0, row=3, sticky='nsew')
back = tkinter.Button(image=bigback_photo, command=lambda: stop_sound(player) | schedule('fromclean'), font=('宋体', 30),height=60)
back.grid(column=2, row=3, sticky='nsew')
sound = load_sound("support/sound.mp3")
player = play_sound(sound)
def start():
remain = hour * 60 * 60 + minute * 60 + second
current_time = datetime.datetime.now().time()
current_datetime = datetime.datetime.combine(datetime.date.today(), current_time)
future_datetime = current_datetime + datetime.timedelta(seconds=remain)
future_time = future_datetime.time().replace(microsecond=0)
updated(future_time)
def times(unit, way):
global hour, minute, second, root
if unit == 'hour':
if way == '+':
if hour >= 23:
pass
else:
hour = hour + 1
elif way == '-':
if hour <= 0:
pass
else:
hour = hour - 1
elif unit == 'minute':
if way == '+':
if minute >= 59 and hour < 23:
hour = hour + 1
minute = minute % 59
elif minute >= 59 and hour >= 23:
pass
else:
minute = minute + 1
elif way == '-':
if minute <= 0:
pass
else:
minute = minute - 1
elif unit == 'second':
if way == '+':
if second >= 59 and minute < 59:
minute = minute + 1
second = second % 59
elif second >= 59 and minute >= 59 and hour < 23:
hour = hour + 1
second = second % 59
minute = minute % 59
elif second >= 59 and minute >= 59 and hour >= 23:
pass
else:
second = second + 1
elif way == '-':
if second <= 0:
pass
else:
second = second - 1
tkinter.Label(text=str(hour).zfill(2), font=('宋体', 50)).grid(column=0, row=1, sticky='nsew')
tkinter.Label(text=str(minute).zfill(2), font=('宋体', 50)).grid(column=1, row=1, sticky='nsew')
tkinter.Label(text=str(second).zfill(2), font=('宋体', 50)).grid(column=2, row=1, sticky='nsew')
root.update()
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=1)
root.grid_columnconfigure(2, weight=1)
step_wid = (500 - root.winfo_width()) / speed
step_hei = (300 - root.winfo_height()) / speed
step_x = (root.winfo_x() - (root.winfo_screenwidth() // 2 - 500 / 2)) / speed
step_y = (root.winfo_y() - (root.winfo_screenheight() // 2 - 300 / 2)) / speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() + step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() - step_x), int(root.winfo_y() - step_y)))
root.update()
root.geometry(
'{}x{}+{}+{}'.format(500, 300, int(root.winfo_screenwidth() // 2 - 500 / 2), int(root.winfo_screenheight() // 2 - 300 / 2)))
def welcome():
global starttime, hour, minute, second, flag,up_photo,down_photo,bigback_photo
for child in root.grid_slaves():
child.grid_remove()
hour = 0
minute = 0
second = 0
flag = False
tkinter.Button(image=up_photo, command=lambda: times('hour', '+'), font=('宋体', 30),height=60).grid(column=0, row=0,
sticky='nsew')
tkinter.Button(image=up_photo, command=lambda: times('minute', '+'), font=('宋体', 30)).grid(column=1, row=0,
sticky='nsew')
tkinter.Button(image=up_photo, command=lambda: times('second', '+'), font=('宋体', 30)).grid(column=2, row=0,
sticky='nsew')
tkinter.Button(image=down_photo, command=lambda: times('hour', '-'), font=('宋体', 30),height=60).grid(column=0, row=2,
sticky='nsew')
tkinter.Button(image=down_photo, command=lambda: times('minute', '-'), font=('宋体', 30)).grid(column=1, row=2,
sticky='nsew')
tkinter.Button(image=down_photo, command=lambda: times('second', '-'), font=('宋体', 30)).grid(column=2, row=2,sticky='nsew')
tkinter.Label(text=str(hour).zfill(2), font=('宋体', 50)).grid(column=0, row=1, sticky='nsew')
tkinter.Label(text=str(minute).zfill(2), font=('宋体', 50)).grid(column=1, row=1, sticky='nsew')
tkinter.Label(text=str(second).zfill(2), font=('宋体', 50)).grid(column=2, row=1, sticky='nsew')
starttime = tkinter.Button(image=star_photo, command=lambda: start(), font=('宋体', 30),height=60)
starttime.grid(column=0, row=3, columnspan=2, sticky='nsew')
back = tkinter.Button(image=bigback_photo, command=lambda: schedule('fromclean'), font=('宋体', 30))
back.grid(column=2, row=3, sticky='nsew')
root.mainloop()
welcome()
def homework():
global z,toplevel,back_photo,speed
z=True
image = Image.open("support/smile.jpg")
photo = ImageTk.PhotoImage(image)
def look():
global cross_photo
for child in root.grid_slaves():
child.grid_remove()
for t in root.place_slaves():
t.destroy()
tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne')
work=[]
copylist = ''
subjects = open('support/subjects', 'r').read().splitlines()
for i, subject in enumerate(subjects):
if str(d.date()) + subject in os.listdir('support/homework/'):
with open('support/homework/' + str(d.date()) + subject, 'r+') as f:
work.append(subject+'')
copylist = copylist + subject
l=1
for x in f.readlines():
work.append(x)
copylist = copylist + str(l)+')'+ x
l=l+1
copylist = copylist + '\n'
pyperclip.copy(copylist)
i=9
doc = Document()
paragraph3 = doc.add_paragraph()
paragraph3.add_run(copylist)
doc.save('support/'+str(d.date())+'作业.docx')
tkinter.Message(root,text=copylist,font=('黑体', 24)).grid(column=i,row=0,pady=30,ipadx=root.winfo_width())
tkinter.Button(root, text='查看word',command=lambda :os.startfile(os.path.normpath('support/'+str(d.date())+'作业.docx'))).place(relx=0,rely=1,anchor='sw')
tkinter.Button(root, image=back_photo, command=lambda: choice_subject()).place(relx=0, rely=0,
anchor='nw')
root.update()
def add_subject(a):
with open('support/subjects', 'r+') as h:
if a+'\n' in h.readlines():
tkinter.messagebox.showwarning('已存在',a+'已存在')
h.close()
elif a == '':
return False
else:
with open('support/subjects', 'a+') as g:
g.write(str(a) + '\n')
g.close()
choice_book(a)
def add_work_write(sub,book,info):
global label_img
with open('support/homework/'+str(d.date())+sub,'a+') as f:
f.write(book+info+'\n')
pass
try:
label_img = tkinter.Label(root, image=photo, width=30, height=30)
label_img.place(relx=0,rely=1,anchor='sw')
root.update()
add_work(sub,book)
except:
pass
def delete_homework(sub,subject,book):
with open('support/homework/'+str(d.date())+sub, 'r') as file:
lines = file.readlines()
for i, line in enumerate(lines):
if line.strip() == subject:
del lines[i]
break
with open('support/homework/'+str(d.date())+sub, 'w') as file:
file.writelines(lines)
add_work(sub,book)
def handle_return(event):
if event.keysym == 'Return':
return 'break'
def add_work(sub,book):
global cross_photo
for child in root.grid_slaves():
child.grid_remove()
for t in root.place_slaves():
t.destroy()
try:
subjects = open('support/homework/'+str(d.date())+sub, 'r+').read().splitlines()
except:
with open('support/homework/'+str(d.date())+sub, 'w+') as f:
pass
subjects = open('support/homework/'+str(d.date())+sub, 'r+').read().splitlines()
i=2
for i, subject in enumerate(subjects):
print('到这儿了')
button = tkinter.Label(root, text=subject,justify='left',wraplength=160)
button.grid(row=i + 1, column=0, ipadx=50, pady=5,sticky='w')
button = tkinter.Button(root, image=cross_photo,command=lambda subject=subject: delete_homework(sub,subject,book))
button.grid(row=i + 1, column=1, ipadx=1, pady=5)
print('到这儿了')
tkinter.Button(root, image=back_photo, command=lambda: choice_book(sub)).place(relx=0, rely=0,
anchor='nw')
tkinter.Label(root, text=sub+' '+book+'\n' +'请输入具体页数或题号').grid(row=0, column=0, ipadx=15, pady=10, columnspan=3)
ppp = tkinter.Text(root, width=20,height=20)
ppp.bind('<Key>', handle_return)
ppp.grid(row=i+2, column=0, ipadx=30,sticky='e',padx=10)
tkinter.Button(root, image=save_and_continue_photo, command=lambda: add_work_write(sub,book,ppp.get(1.0,END).strip()),bg='white',activebackground='white',fg='white').grid(row=i+3,
column=0,
ipadx=15, pady=10)
tkinter.Button(root, text='X', command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne')
try:
root.after(3000,lambda :label_img.destroy())
except:
pass
def add_book(sub,book):
with open('support/' + sub, 'r+') as f:
if book == '':
return False
elif book+'\n' in f.readlines():
tkinter.messagebox.showwarning('已存在', book + '已存在')
else:
with open('support/' + sub, 'a+') as g:
g.write(book + '\n')
g.close()
f.close()
add_work(sub,book)
def choice_book(sub):
for child in root.grid_slaves():
child.grid_remove()
for t in root.place_slaves():
t.destroy()
try:
subjects = open('support/'+sub, 'r+').read().splitlines()
except:
with open('support/'+sub, 'w+') as f:
f.write('')
f.close()
subjects = open('support/' + sub, 'r+').read().splitlines()
i=2
tkinter.Button(root, text='X', command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne')
tkinter.Label(root, text='\n\n'+sub + '\n' + '选择或输入书名或卷名\n可将此栏目中的内容添加为常用书').grid(row=0, column=0,
ipadx=15,
pady=10,
columnspan=3)
for i, subject in enumerate(subjects):
button = tkinter.Button(root, text=subject,
command=lambda subject=subject: add_work(sub,subject))
button.grid(row=i + 1, column=0, ipadx=15, pady=10, columnspan=3)
tkinter.Button(root, image=back_photo, command=lambda: choice_subject()).place(relx=0, rely=0,
anchor='nw')
ppp = tkinter.Entry(root, width=10)
ppp.grid(row=i + 2, column=0, ipadx=15,columnspan=3)
tkinter.Button(root, text='确定并保存为常用书', command=lambda: add_book(sub,ppp.get())).grid(row=i + 3, column=0,
ipadx=15, pady=10,columnspan=3)
tkinter.Button(root, text='确定', command=lambda: add_work(sub,ppp.get())).grid(row=i + 4,
column=0,
ipadx=15, pady=10,columnspan=3)
root.update()
pass
def window_close_handle():
global z,toplevel
z=False
root.destroy()
try:
toplevel.overrideredirect(1)
except:
pass
for x in root.place_slaves():
x.place_forget()
root.title('添加作业')
root.protocol('WM_DELETE_WINDOW', window_close_handle)
root.update()
win_width = 300
win_height = 800
step_wid=(300-root.winfo_width())/speed
step_hei=(800-root.winfo_height())/speed
win_x = screen_width - win_width
win_y = root.winfo_screenheight() // 2 - win_height // 2
step_x = ((screen_width - win_width) - root.winfo_x()) / speed
step_y = ((root.winfo_screenheight() // 2 - win_height // 2) - root.winfo_y()) / speed
for x in range(speed):
wid=root.winfo_width()+step_wid
hei=root.winfo_height()+step_hei
root.geometry('{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x()+step_x), int(root.winfo_y()+step_y)))
root.update()
root.winfo_x(), root.winfo_y(), root.winfo_width(), root.winfo_height()
i = 2
j = 0.2
def choice_subject():
root.grid_rowconfigure(1, weight=0)
root.grid_columnconfigure(0, weight=0)
root.grid_columnconfigure(1, weight=0)
root.grid_columnconfigure(2, weight=0)
global z
for child in root.grid_slaves():
child.grid_remove()
for t in root.place_slaves():
t.destroy()
tkinter.Button(root, text='X', command=lambda :schedule('fromhomework')).place(relx=1, rely=0, anchor='ne')
subjects = open('support/subjects', 'r').read().splitlines()
for i, subject in enumerate(subjects):
tkinter.Label(root, text='请选择科目').grid(row=0, column=0, ipadx=15, pady=10, columnspan=2)
button = tkinter.Button(root, text=subject,
command=lambda subject=subject: choice_book(subject))
button.grid(row=i + 1, column=0, ipadx=15, pady=10, columnspan=2)
ppp = tkinter.Entry(root, width=10)
ppp.grid(row=i + 2, column=0, ipadx=15)
tkinter.Button(root, text='下一项(自动保存)', command=lambda: add_subject(ppp.get())).grid(row=i + 2, column=1,
ipadx=15, pady=10)
tkinter.Button(root, text='查看并复制', command=lambda: look()).place(relx=1, rely=1, anchor='se')
root.update()
choice_subject()
def settings():
global speed
for btn in root.place_slaves():
btn.destroy()
for x in root.grid_slaves():
x.grid_remove()
def speed(x):
global speed
speed=int(x)
print(speed)
print(speed)
tkinter.Label(root, text='动画速度').grid(row=0, column=0)
spe=tkinter.Entry(root, width=30)
spe.grid(row=0, column=1)
tkinter.Button(root, text='确定', command=lambda: speed(spe.get())).grid(row=0, column=2)
tkinter.Button(root, text='X', command=lambda: schedule('fromchoice')).place(relx=1, rely=0, anchor='ne')
def choice(fromwhere):
global info,canceltopping,zhou,h,d,photo,label_img,chosed,shouldnot,password,speed
root.wm_attributes('-topmost', 1)
top.destroy()
for btn in root.place_slaves():
btn.destroy()
for x in root.grid_slaves():
x.grid_remove()
if not check_class():
now='1'
else:
now=check_class()
root.overrideredirect(1)
if fromwhere=='fromschedule':
step_wid = (400 - root.winfo_width()) / speed
step_hei = (root.winfo_height() - 300) / speed
win_width = 400
win_height = 300
win_x = screen_width - win_width
win_y = root.winfo_screenheight() // 2 - win_height // 2
step_x = ((screen_width - win_width) - root.winfo_x()) / speed
step_y = ((root.winfo_screenheight() // 2 - win_height // 2)-root.winfo_y()) / speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() - step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() + step_x), int(root.winfo_y() + step_y)))
root.update()
root.geometry('{}x{}+{}+{}'.format(win_width, win_height, win_x, win_y))
elif fromwhere=='fromtab':
step_wid = (400 - root.winfo_width()) / speed
step_hei = (root.winfo_height() - 300) / speed
step_x = root.winfo_x()/ speed
step_y = root.winfo_y()/ speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() - step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() - step_x), int(root.winfo_y() - step_y)))
root.update()
root.geometry('{}x{}+{}+{}'.format(400, 300, 0, 0))
root.update()
root.title('随机选人')
global list
list = []
status = '开始'
back = tkinter.Button(text='返回', command=lambda: schedule('fromchoice'))
back.place(relx=1, rely=0, anchor='ne')
verify = tkinter.Button(text='倒计时', command=lambda: countdown())
verify.place(relx=0, rely=0, anchor='nw')
set = tkinter.Button(text='设置', command=lambda: settings())
set.place(relx=0.5, rely=0, anchor='n')
root.update()
inn = tkinter.Label(text='正在处理……')
inn.place(relx=0.5, rely=0.5, anchor='center')
with open('support/record.txt','r') as k:
for re in k.readlines():
if not re.strip('\n') in chosed:
chosed.append(re.strip('\n'))
k.close()
try:
try:
with open('support/' + now + '.txt', 'r') as f:
inf = tkinter.Label(
text='正在使用人名单:'+now)
inf.place(relx=0.5, rely=0.6, anchor='center')
for x in f.readlines():
x = x.strip('\n')
list.append(x)
info = str(len(list))
f.close()
except:
with open('support/1.txt', 'r') as f:
inf = tkinter.Label(
text='正在使用全体人名单')
inf.place(relx=0.5, rely=0.6, anchor='center')
for x in f.readlines():
x = x.strip('\n')
list.append(x)
info = str(len(list))
f.close()
with open('support/journal.log') as c:
jour=[]
for x in c.readlines():
jour.append(x)
c.close()
for x in range(len(jour) - 1, -1, -1):
if '当前有' in jour[x]:
file_name =jour[x].split('当前有')[1]
episode_name = file_name.split('')[0]
break
for y in range(len(jour)-1,-1,-1):
if '人名单sha256:' in jour[y]:
fi=jour[y].split('sha256:')
break
zz=file_sha256(r'support/1.txt')+'\n'
try:
try:
if zz != fi[1]:
if rest():
on_button_click('人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。',
'')
elif not rest():
on_button_click('人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。',
'pppp')
else:
password = True
except:
log('人名单sha256:' + file_sha256(r'support/1.txt'),'info')
password=True
except:
pass
if (rest()) or (not rest() and password==True):
log('人名单sha256:'+file_sha256(r'support/1.txt'),'info')
log('当前有' + str(len(list)) + '','info')
password=False
except Exception as e:
on_button_click('没有找到人名单文件或因\n'+str(e),'')
log('人名单文件不存在','info')
schedule('fromchoice')
root.quit()
try:
for z in range(len(jour)-1,-1,-1):
if '操作后sha256:' in jour[z]:
ooo=(jour[z].split('sha256:'))[1]
break
sha=file_sha256(r'support/record.txt')+'\n'
try:
if ooo != sha:
if rest():
on_button_click('抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。', '')
elif not rest():
on_button_click('抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。','pppp')
else:
password=True
if (rest()) or (not rest() and password == True):
log('操作后sha256:' + file_sha256(r'support/record.txt'),'info')
password = False
except:
pass
except:
pass
try:
with open('support/config.ini','r+') as file:
for z in file.readlines():
if '日志处理后sha256:' in jour[z]:
jourlog = (jour[z].split('sha256:'))[1]
break
sha = file_sha256(r'support/journal.log') + '\n'
try:
if jourlog != sha:
if rest():
on_button_click('日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。',
'')
elif not rest():
on_button_click('日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。',
'pppp')
else:
password = True
if (rest()) or (not rest() and password == True):
log('', 'info')
password = False
except:
pass
except:
pass
try:
if int(episode_name) != len(list):
on_button_click('人名单中的人数\n与上次运行时不一致,\n请检查人名单是否被篡改。\n按确定以继续。','')
for i in set(list):
if list.count(i) > 1:
if on_button_click('在人名单文件中,'+i+'出现了'+str(list.count(i))+'次,\n请检查人名单是否被篡改。\n重复的元素将会引发程序错误,\n在删除重复的元素之前请勿运行此模块。\n按确定以退出。',''):
schedule('fromchoice')
elif i in shouldnot:
on_button_click('人名单中出现不该出现的\n"'+i+'"\n请检查人名单是否被篡改。\n按确定以继续。','')
except:
pass
def stop(r):
global flag, status, list, info, a, chosed, inf
flag = True
status = '开始'
if not rest():
inf = tkinter.Label(
text='当前有' + info + '人。\n现在处于下课时间,\n抽到的人将不会添加到已抽中列表。')
else:
chosed.append(r)
log('本次抽中' + r,'info')
with open('support/record.txt','a+') as p:
p.write(r+'\n')
p.close()
log('操作后sha256:'+file_sha256(r'support/record.txt'),'info')
inf = tkinter.Label(
text='当前有' + info + '人。历史上已抽中' + str(len(chosed)) + '人。\n在抽中所有人前,抽中的人不会再次出现。')
inf.place(relx=0.5, rely=0.6, anchor='center')
start = tkinter.Button(text=status, command=lambda: main(), font=('宋体', 24), width=20)
start.place(relx=0.5, rely=0.8, anchor='center')
def main():
global flag, root, list, status, info, a, chosed, inf
try:
inf.destroy()
except:
pass
flag = False
status = '就你了'
start = tkinter.Button(text=status, command=lambda: stop(list[r]), font=('宋体', 24), width=20)
start.place(relx=0.5, rely=0.8, anchor='center')
while not flag:
r = random.randint(0, len(list) - 1)
if len(chosed) == len(list):
chosed.clear()
with open('support/record.txt','a+')as g:
g.truncate(0)
g.close()
log('操作后sha256:' + file_sha256(r'support/record.txt'),'info')
if list[r] not in chosed:
try:
a.destroy()
except:
pass
a = tkinter.Label(text=list[r], width=30, font=('华文行楷', 72))
a.place(relx=0.5, rely=0.35, anchor='center')
root.update()
time.sleep(0.01)
flag = False
status = '开始'
inn.destroy()
a = tkinter.Label(text='保持紧张', width=30, font=('华文行楷', 72))
a.place(relx=0.5, rely=0.35, anchor='center')
start = tkinter.Button(text=status, command=lambda: main(), font=('宋体', 24), width=20)
start.place(relx=0.5, rely=0.8, anchor='center')
def check_resttime():
global zhou, d
try:
excel = xlrd.open_workbook("support/时刻表.xls")
sheet = excel.sheet_by_index(0)
rows: list = sheet.row_values(0)
index = rows.index('时刻表')
listindes = sheet.col_values(index)
for x in range(1, len(listindes)):
a = listindes[x].split('-')
start_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[0], '%Y-%m-%d%H:%M')
end_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + a[1], '%Y-%m-%d%H:%M')
now_time = datetime.datetime.now()
if start_time < now_time < end_time:
delta = end_time - now_time
seconds = delta.total_seconds()
return int(seconds)
return 2400
except:
return 2400
def schedule(fr):
global thu,other,zhou,d,canceltopping,photo,label_img,lose,hh,h,no,top,z,speed
root.wm_attributes('-topmost', 0)
z = False
for btn in root.place_slaves():
btn.destroy()
for btn in root.grid_slaves():
btn.grid_remove()
if lose==[]:
pass
else:
a='缺少关键组件:\n'
for x in lose:
a=a+x+'\n'
on_button_click(a,'')
lose=[]
if fr=='fromclean':
step_wid = (50 - root.winfo_width()) / speed
step_hei = (500 - root.winfo_height()) / speed
step_x = (root.winfo_x() - (screen_width)) / speed
step_y = ((root.winfo_y() - root.winfo_screenheight() / 2) + 250) / speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() + step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() - step_x), int(root.winfo_y() - step_y)))
root.update()
root.geometry(
'{}x{}+{}+{}'.format(50, 500, screen_width - 50, root.winfo_screenheight() // 2 - 500 // 2))
elif fr=='fromchoice':
step_wid = (50 - root.winfo_width()) / speed
step_hei = (500 - root.winfo_height()) / speed
step_x = (root.winfo_x() - (screen_width)) / speed
step_y = ((root.winfo_y() - root.winfo_screenheight() / 2) + 250) / speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() + step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() - step_x), int(root.winfo_y() - step_y)))
root.update()
root.geometry(
'{}x{}+{}+{}'.format(50, 500, screen_width - 50, root.winfo_screenheight() // 2 - 500 // 2))
elif fr=='fromhomework':
step_wid = (50 - root.winfo_width()) / speed
step_hei = (500 - root.winfo_height()) / speed
step_x = (root.winfo_x()-(screen_width)) / speed
step_y = ((root.winfo_y() - root.winfo_screenheight() / 2)+250) / speed
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() + step_hei
root.geometry(
'{}x{}+{}+{}'.format(int(wid), int(hei), int(root.winfo_x() - step_x), int(root.winfo_y() - step_y)))
root.update()
root.geometry(
'{}x{}+{}+{}'.format(50, 500, screen_width - 50,root.winfo_screenheight() // 2 - 500 // 2))
root.update()
root.title('课程表')
root.resizable(0, 0)
root.overrideredirect(1)
try:
excel = xlrd.open_workbook("support/课程表.xls")
sheet = excel.sheet_by_index(0)
rows: list = sheet.row_values(0)
index = rows.index(zhou[d.weekday()])
listindes = sheet.col_values(index)
except:
on_button_click('请确认课程表文件\n存在且格式正确','')
log('课程表文件不存在','error')
root.quit()
g=0.113
if len(listindes)==9:
for i in range(1, len(listindes)):
if '/' not in listindes[i]:
zxs = tkinter.Label(text=listindes[i][0], width=15, font=('华文行楷', 40))
else:
zxs = tkinter.Label(text=listindes[i], width=15, font=('华文行楷', 20))
zxs.place(relx=0.5, rely=g, anchor='center')
g = g + 0.113
elif len(listindes)==10:
for i in range(1, len(listindes)):
if '/' not in listindes[i]:
zxs = tkinter.Label(text=listindes[i][0], width=15, font=('华文行楷', 40))
else:
zxs = tkinter.Label(text=listindes[i], width=15, font=('华文行楷', 20))
zxs.place(relx=0.5, rely=g, anchor='center')
g = g + 0.093
else:
for i in range(1, len(listindes)):
if '/' not in listindes[i]:
zxs = tkinter.Label(text=listindes[i][0], width=15, font=('华文行楷', 40))
else:
zxs = tkinter.Label(text=listindes[i], width=15, font=('华文行楷', 20))
zxs.place(relx=0.5, rely=g, anchor='center')
g = g + 0.106
listindes.clear()
y = tkinter.Button(text=zhou[d.weekday()], width=15, command=lambda :choice('fromschedule'))
y.place(relx=0.5, rely=1, anchor='s')
global h
h = tkinter.Button(text='添加作业', command=lambda: homework())
h.place(relx=0.5, rely=0, anchor='n')
top=tkinter.Toplevel()
top.resizable(0, 0)
top.overrideredirect(1)
top.wm_attributes('-topmost', 1)
top.attributes('-alpha', 0.5)
btn=tkinter.Button(top,text='点名器',command=lambda :choice('fromtab'),font=('宋体',8))
btn.place(relx=0,rely=0,anchor='nw')
root.update_idletasks()
btn_width = btn.winfo_width()
btn_height = btn.winfo_height()
top.geometry("{}x{}".format(btn_width, btn_height))
root.wm_attributes('-topmost', 0)
root.mainloop()
def clean():
global fin,a,ll,lose
ll='正在清理文件'
fin=False
a = 0
current_dir = os.getcwd()
uncommon_dir = os.path.join(current_dir, '不常用的文件')
if not os.path.exists(uncommon_dir):
os.mkdir(uncommon_dir)
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
for filename in os.listdir(current_dir):
filepath = os.path.join(current_dir, filename)
ll='检查'+filepath
ll=filename
if filename == '不常用的文件':
ll = '跳过' + filename
elif filename == '文件归档.py' or filename=='loading.gif' or filename=='smile.jpg' or filename=='课程表.xls' or filename=='时间表.xls' or filename=='1.txt' or filename=='journal.log' or filename=='record.txt'or os.path.isdir(filepath) == 'support' or filename.endswith('.exe') or filename.endswith('.lnk') or filename.endswith('.ini') or ('nodelete' in filename) or ('support' in filename):
ll='跳过'+filename
elif os.path.getmtime(filepath) < one_week_ago.timestamp():
ll='移动'+filename
try:
shutil.move(filepath, os.path.join(uncommon_dir, filename))
log('移动了'+filename,'info')
except Exception as e:
log('移动'+str(filename)+'失败,因为'+str(e),'warning')
a = a + 1
else:
ll=filename+'未到过期时间'
ll='正在检查程序组件'
x=os.listdir('support')
list=['smile.jpg','temp.txt','课程表.xls','时间表.xls','时刻表.xls','1.txt','journal.log','record.txt','config.ini']
lose=[]
for y in list:
ll='检查'+y
if y in x:
ll='存在'+y
else:
ll='缺少'+y
lose.append(y)
fin=True
def report():
pass
def ver():
with open('support/temp.txt') as f:
for x in f.readlines():
f.seek(0)
if x=='True':
'检测到了True'
return True
return False
def taskmgr():
windows = pygetwindow.getAllTitles()
for window_title in windows:
try:
window = pygetwindow.getWindowsWithTitle(window_title)[0]
except Exception as e:
log(str(e)+'line 849', 'error')
try:
if window.title == 'Windows 任务管理器' or window.title == '任务管理器' or window.title == 'Windows任务管理器':
tsk = tkinter.Toplevel()
tsk.overrideredirect(1)
tsk.wm_attributes('-topmost', 1)
leb = tkinter.Message(tsk,
text='禁止使用任务管理器如需使用请在随机选人模块中验证密码成功后窗口自动消失有效期3分钟。如无密码关闭任务管理器窗口后此窗口自动消失。此程序无权限关闭任务管理器窗口请自行在任务栏关闭。',
font=('仿宋', 24))
leb.place(relx=0.5, rely=0.5, anchor='center')
while not ver():
try:
tsk.geometry('{}x{}+{}+{}'.format(window.width, window.height, window.left, window.top))
tsk.update()
time.sleep(0.1)
except:
root.destroy()
break
else:
try:
tsk.destroy()
time.sleep(180)
except:
pass
except Exception as e:
log(str(e)+'line 874', 'error')
time.sleep(1)
def check_score():
while 1:
if not rest():
windows = pygetwindow.getAllTitles()
for window_title in windows:
try:
window = pygetwindow.getWindowsWithTitle(window_title)[0]
except Exception as e:
log(e,'error')
try:
if window.title == '成绩单':
window.close()
elif window.title =='任务管理器' or window.title == '任务管理器' or window.title == 'Windows任务管理器':
try:
if t5.isAlive():
pass
else:
t5 = Thread(target=taskmgr)
t5.start()
except:
t5 = Thread(target=taskmgr)
t5.start()
except Exception as e:
log(str(e)+'line 899', 'error')
time.sleep(0.3)
else:
time.sleep(check_resttime())
speed=50
t1 = Thread(target=clean, args=())
t2 = Thread(target=loading)
t4 = Thread(target=check_score)
t5 = Thread(target=urge)
t1.start()
t2.start()
t4.start()
t5.start()