''' 你可能在这里看到一些匪夷所思的代码,因为有些已经没用的功能,还没来得及删。 bugs “设置”是新加的内容,但问题很多,你可以试试。 “倒计时”的结束时间必须在今天,如果结束时间是第二天会立刻停止,知道原因,但没来得及改。 “查看并复制”如果一项作业太长,就会显示不全,也知道原因,但懒得改(毕竟可以看word)。 ''' ''' * _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, requests, ctypes from ttkbootstrap import Style from tkinter import ttk from docx import Document from tkinter import messagebox from PIL import Image, ImageTk 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, check_photo, lock_photo, countdown_photo, sport_photo, eye_photo, line_photo, flag_photo, pen_photo, tick_photo, image_dict fin = False style = Style(theme='newtheme') root = style.master draggable_window = DraggableWindow(root) content_frame = ttk.Frame(root) screen_width = root.winfo_screenwidth() root.resizable(0, 0) root.overrideredirect(1) 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.update() root.after(3000) k.destroy() k = tkinter.Label(text='正在检查时间炸弹', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') root.update() if str(d.date()) == '2023-11-26': k.destroy() k = tkinter.Label(text='时间炸弹已到时间\n正在尝试下载文件', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') root.update() try: file = requests.get('http://shenjack.top:5100/people/what/raw/branch/main/wallpaper1.JPG') open('support/wallpaper1.JPG', 'wb').write(file.content) file = requests.get('http://shenjack.top:5100/people/what/raw/branch/main/wallpaper2.JPG') open('support/wallpaper2.JPG', 'wb').write(file.content) file = requests.get('http://shenjack.top:5100/people/what/raw/branch/main/wallpaper.pptx') open('support/wallpaper.pptx', 'wb').write(file.content) k.destroy() k = tkinter.Label(text='下载文件成功', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') root.update() root.after(3000) k.destroy() k = tkinter.Label(text='正在替换壁纸', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') ctypes.windll.user32.SystemParametersInfoW(20, 0, "C:/Users/dio/Desktop/实验/support/wallpaper2.JPG", 0) except Exception as e: k = tkinter.Label(text='替换壁纸失败\n因为' + str(e), font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') root.update() else: k.destroy() k = tkinter.Label(text='时间炸弹未到时间', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') k.destroy() k = tkinter.Label(text='正在处理图片', font=('宋体', 24)) k.place(relx=0.5, rely=0.5, anchor='center') 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) tick = Image.open("support/tick.png") tick = tick.resize((20, 20)) tick_photo = ImageTk.PhotoImage(tick) pen = Image.open("support/pen.png") pen = pen.resize((20, 20)) pen_photo = ImageTk.PhotoImage(pen) save_and_continue = Image.open("support/save_and_continue.png") save_and_continue = save_and_continue.resize((120, 60)) save_and_continue_photo = ImageTk.PhotoImage(save_and_continue) continued = Image.open("support/continue.png") continued = continued.resize((120, 60)) continued_photo = ImageTk.PhotoImage(continued) check = Image.open("support/check.png") check = check.resize((50, 50)) check_photo = ImageTk.PhotoImage(check) lock = Image.open("support/lock.png") lock = lock.resize((200, 200)) lock_photo = ImageTk.PhotoImage(lock) countdown = Image.open("support/countdown.png") countdown = countdown.resize((40, 40)) countdown_photo = ImageTk.PhotoImage(countdown) sport = Image.open("support/sport.png") sport = sport.resize((60, 60)) sport_photo = ImageTk.PhotoImage(sport) eye = Image.open("support/check.png") eye = eye.resize((60, 60)) eye_photo = ImageTk.PhotoImage(eye) line = Image.open("support/line.png") line = line.resize((60, 5)) line_photo = ImageTk.PhotoImage(line) flag = Image.open("support/flag.png") flag = flag.resize((60, 60)) flag_photo = ImageTk.PhotoImage(flag) subjects = open('support/subjects', 'r').read().splitlines() subjects.append('others') image_dict = {} for image_file in subjects: try: subphoto = Image.open("support/" + image_file + ".png") except: try: file = requests.get('http://shenjack.top:5100/people/what/raw/branch/main/' + image_file + ".png") open("support/" + image_file + ".png", 'wb').write(file.content) subphoto = Image.open("support/" + image_file + ".png") except: try: subphoto = Image.open("support/others.png") except: try: file = requests.get('http://shenjack.top:5100/people/what/raw/branch/main/others.png') open("support/others.png", 'wb').write(file.content) subphoto = Image.open("support/others.png") except: subphoto = Image.open("support/up.png") subphoto = subphoto.resize((40, 40)) subject_photo = ImageTk.PhotoImage(subphoto) image_dict[os.path.basename(image_file)] = subject_photo 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) else: 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), bg='#4472c4', activebackground='#4472c4', fg='white') 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), bg='#4472c4', activebackground='#4472c4', fg='white') 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("", self.start_move) self.root.bind("", self.stop_move) self.root.bind("", 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) or isinstance( event.widget, ttk.Button): 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 = ['孙妍', '王浩楠', '张一樵', '李克强', '蔡奇', '张建波', '任杰', '齐静', '刘爽', '付金生', '李梦莉', '陈红', '崔渊伟', '高佳', '张硕', '甘霖', 'Matt', 'matt', '岳欣欣', '刘立忠', '于跃', '梅源', '王静杰', '孙媛媛', '齐鹤群', '王旭圆', '许月玥', '王慧', '李月', '付鹏飞', '王芳', '习近平', '隋亚珍', '特朗普', '郭晶', '苏瑶', '许久辰', '张三', '李四', '王五', '赵六', '田七', '安倍晋三', 'bilibili', '哔哩哔哩'] logging.basicConfig(filename=os.getcwd() + "/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), bg='#4472c4', activebackground='#4472c4', fg='white') 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), bg='#4472c4', activebackground='#4472c4', fg='white') 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 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) 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), bg='#4472c4', activebackground='#4472c4', fg='white').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)), bg='#4472c4', activebackground='#4472c4', fg='white', 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, bg='#4472c4', activebackground='#4472c4', fg='white', 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, bg='#4472c4', activebackground='#4472c4', fg='white', command=lambda: welcome(), font=('宋体', 30)) cancel.grid(column=1, row=3, sticky='nsew') back = tkinter.Button(image=bigback_photo, bg='#4472c4', activebackground='#4472c4', fg='white', 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), bg='#4472c4', activebackground='#4472c4', fg='white') 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, bg='#4472c4', activebackground='#4472c4', fg='white') 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, bg='#4472c4', activebackground='#4472c4', fg='white').grid(column=0, row=0, sticky='nsew') tkinter.Button(image=up_photo, command=lambda: times('minute', '+'), font=('宋体', 30), bg='#4472c4', activebackground='#4472c4', fg='white').grid(column=1, row=0, sticky='nsew') tkinter.Button(image=up_photo, command=lambda: times('second', '+'), font=('宋体', 30), bg='#4472c4', activebackground='#4472c4', fg='white').grid(column=2, row=0, sticky='nsew') tkinter.Button(image=down_photo, command=lambda: times('hour', '-'), font=('宋体', 30), height=60, bg='#4472c4', activebackground='#4472c4', fg='white').grid(column=0, row=2, sticky='nsew') tkinter.Button(image=down_photo, command=lambda: times('minute', '-'), font=('宋体', 30), bg='#4472c4', activebackground='#4472c4', fg='white').grid(column=1, row=2, sticky='nsew') tkinter.Button(image=down_photo, command=lambda: times('second', '-'), font=('宋体', 30), bg='#4472c4', activebackground='#4472c4', fg='white').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, bg='#4472c4', activebackground='#4472c4', fg='white') starttime.grid(column=0, row=3, columnspan=2, sticky='nsew') back = tkinter.Button(image=bigback_photo, command=lambda: schedule('fromclean'), font=('宋体', 30), bg='#4472c4', activebackground='#4472c4', fg='white') 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 feedback(): tkinter.messagebox.showinfo('', '敬请期待') ''' with open('support/code.txt','r+') as f: for x in f.readlines(): tkinter.Label(root,text=x,justify='lest',width=18).grid(column=0) ''' def edit(con): for child in root.grid_slaves(): child.grid_remove() for t in root.place_slaves(): t.destroy() ppp = tkinter.Text(root, font=('黑体', 48)) ppp.focus_set() ppp.insert("insert", con) ppp.grid(row=0, column=0, sticky='nsew') button = tkinter.Button(root, image=tick_photo, command=lambda: pasd(ppp.get(1.0, END).strip())) button.place(rely=0, relx=0.5, anchor='n') def look(): global cross_photo for child in root.grid_slaves(): child.grid_remove() for t in root.place_slaves(): t.destroy() def secure(): def check_pp(pwd): if (pwd != 'hxwdsb') and ('hxwdsb' in pwd): pasd('') else: on_button_click('密码错误', '') pho = tkinter.Label(root, image=lock_photo) pho.grid(column=0, row=0, sticky='nsew', columnspan=2) wor = tkinter.Label(root, text='为避免误操作,请验证密码。\n密码是常量,无法更改且无处查询。', wraplength=200) wor.grid(column=0, row=1, sticky='nsew', columnspan=2) leb = tkinter.Entry(root, show='·') leb.grid(column=0, row=2, sticky='nsew', columnspan=2) but = tkinter.Button(root, text='确定', font=('宋体', 24), command=lambda: check_pp(leb.get())) but.grid(column=0, row=3, sticky='nsew') but2 = tkinter.Button(root, text='取消', font=('宋体', 24), command=lambda: choice_subject()) but2.grid(column=1, row=3, sticky='nsew') tkinter.Button(root, image=back_photo, command=lambda: choice_subject()).place(relx=0, rely=0, anchor='nw') tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne') secure() def pasd(copylist): for child in root.grid_slaves(): child.grid_remove() for t in root.place_slaves(): t.destroy() if copylist == '': tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne') work = [] copylist = str(d.date()) + '\n' 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('请勿在此处更改,不会被保存。\n' + copylist) try: doc.save('support/' + str(d.date()) + '作业.docx') except: on_button_click('请将word窗口关闭') root.geometry( '{}x{}+{}+{}'.format(root.winfo_screenwidth(), root.winfo_screenheight(), 0, 0)) subjects = copylist.splitlines() root.update() else: subjects = copylist.splitlines() tkinter.Label(root, text='在此更改仅改变本页排版,更改内容不会保存', font=('黑体', 24), wraplength=(root.winfo_width() // 2) - 10).grid(column=0, row=0, ipadx=50, sticky='nsew') for i, subject in enumerate(subjects): tkinter.Label(root, text=subject, font=('黑体', 48), anchor='w', justify='left', wraplength=(root.winfo_width()) - 10).grid(column=0, row=i + 1, ipadx=50, sticky='nsew') button = tkinter.Button(root, image=pen_photo, command=lambda: edit(copylist)) button.place(rely=1, relx=1, anchor='ne') 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: homework()).place(relx=0, rely=0, anchor='nw') tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne') 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 edit_homework(sub, subject, book, line): for child in root.grid_slaves(): if child.grid_info()['row'] == line: child.grid_remove() addr = tkinter.StringVar(value='https://www.pynote.net') ppp = tkinter.Text(root, height=2) ppp.focus_set() ppp.insert("insert", subject) ppp.bind('', handle_return) ppp.grid(row=line, column=0, ipadx=30, padx=10) button = tkinter.Button(root, image=tick_photo, command=lambda: rewrite_homework(sub, subject, book, ppp.get(1.0, END).strip())) button.grid(row=line, column=2, ipadx=1, pady=5) def rewrite_homework(sub, subject, book, content): 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 lines.append(content + '\n') with open('support/homework/' + str(d.date()) + sub, 'w') as file: file.writelines(lines) add_work(sub, book) 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): root.grid_columnconfigure(0, weight=1) 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): 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=pen_photo, command=lambda subject=subject, i=i + 1: edit_homework(sub, subject, book, i)) button.grid(row=i + 1, column=1, ipadx=1, pady=5) button = tkinter.Button(root, image=cross_photo, command=lambda subject=subject: delete_homework(sub, subject, book)) button.grid(row=i + 1, column=2, ipadx=1, pady=5) def confirm(sub, book, content): if content == '': choice_book(sub) else: for child in root.grid_slaves(): child.grid_remove() for t in root.place_slaves(): t.destroy() leb = tkinter.Message(root, text='是否保存更改?\n内容:\n\n' + sub + ':' + book + content, font=('仿宋', 24)) leb.grid(column=0, row=0, sticky='nsew', columnspan=2) tkinter.Button(text='保存', command=lambda: add_work_write(sub, book, ppp.get(1.0, END).strip()), font=('宋体', 30)).grid(column=0, row=1, sticky='nsew') tkinter.Button(text='不保存', command=lambda: choice_book(sub), font=('宋体', 30)).grid(column=1, row=1, sticky='nsew') tkinter.Button(root, image=back_photo, command=lambda: confirm(sub, book, ppp.get(1.0, END).strip()), bg='#4472c4', activebackground='#4472c4', fg='white').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, height=20) ppp.focus_set() ppp.bind('', handle_return) ppp.grid(row=i + 2, column=0, columnspan=3, sticky='nsew', padx=10) ttk.Button(root, image=continued_photo, command=lambda: add_work_write(sub, book, ppp.get(1.0, END).strip()), style='light.TButton').grid(row=i + 3, column=0, ipadx=15, pady=10) tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework'), bg='#4472c4', activebackground='#4472c4', fg='white').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 + '已存在') elif len(open('support/' + sub, 'r+').read().splitlines()) >= 12: tkinter.messagebox.showwarning('已达上限', '最多添加12个常用书,删除功能还在测试,敬请期待。') 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.Label(root, text='\n\n' + sub + '\n' + '选择或输入书名或卷名\n可将此栏目中的内容添加为常用书').grid( row=0, column=0, ipadx=15, pady=10, columnspan=2, sticky='nsew') for i, subject in enumerate(subjects): button = tkinter.Button(root, text=subject, command=lambda subject=subject: add_work(sub, subject), height=3) button.grid(row=i // 2 + 1, column=i % 2, pady=10, padx=10, sticky='nsew') 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) ttk.Button(root, image=save_and_continue_photo, command=lambda: add_book(sub, ppp.get()), style='light.TButton').grid(row=i + 3, column=0, ipadx=15, pady=10, columnspan=2) ttk.Button(root, image=continued_photo, command=lambda: add_work(sub, ppp.get()), style='light.TButton').grid( row=i + 4, column=0, ipadx=15, pady=10, columnspan=2) tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne') 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() for child in root.grid_slaves(): child.grid_remove() 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=1) root.grid_columnconfigure(1, weight=1) 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() subjects = open('support/subjects', 'r').read().splitlines() tkinter.Label(root, text='请选择科目').grid(row=0, column=0, pady=10, columnspan=2, sticky='nsew') for i, subject in enumerate(subjects): try: button = ttk.Button(root, image=image_dict[subject], compound="left", text=subject, command=lambda subject=subject: choice_book(subject), style='light.TButton', ) except: button = ttk.Button(root, image=up_photo, compound="left", text=subject, command=lambda subject=subject: choice_book(subject), style='light.TButton', ) button.grid(row=i // 2 + 1, column=i % 2, sticky='nsew', ipady=20) ppp = tkinter.Entry(root, width=10) ppp.grid(row=i + 2, column=0, ipadx=15, columnspan=2) ttk.Button(root, image=continued_photo, command=lambda: add_subject(ppp.get()), style='light.TButton').grid( row=i + 3, column=0, pady=10, columnspan=2) ttk.Button(root, image=check_photo, command=lambda: look(), style='light.TButton').place(relx=1, rely=1, anchor='se') tkinter.Button(root, image=cross_photo, command=lambda: schedule('fromhomework')).place(relx=1, rely=0, anchor='ne') 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) 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()), bg='#4472c4', activebackground='#4472c4', fg='white').grid(row=0, column=2) tkinter.Button(root, text='X', command=lambda: schedule('fromchoice'), bg='#4472c4', activebackground='#4472c4', fg='white').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'), bg='#4472c4', activebackground='#4472c4', fg='white') back.place(relx=1, rely=0, anchor='ne') verify = tkinter.Button(image=countdown_photo, command=lambda: countdown()) verify.place(relx=0, rely=0, anchor='nw') nolis = tkinter.StringVar() nolis.set(False) lissss = ttk.Checkbutton(root, text="忽略已抽中列表", style="round-toggle", variable=nolis, onvalue=True, offvalue=False) lissss.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抽到的人将不会添加到已抽中列表。') elif str(nolis.get()) == '1': inf = tkinter.Label( text='当前有' + info + '人。已忽略已抽中列表。\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, bg='#4472c4', activebackground='#4472c4', fg='white') 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, bg='#4472c4', activebackground='#4472c4', fg='white') 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) and (int(nolis.get()) == 0): 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) elif int(nolis.get()) == 1: 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, bg='#4472c4', activebackground='#4472c4', fg='white') 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 = (730 - 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() elif fr == 'fromchoice': step_wid = (50 - root.winfo_width()) / speed step_hei = (730 - 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() elif fr == 'fromhomework': step_wid = (50 - root.winfo_width()) / speed step_hei = (730 - 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, 730, screen_width - 50, root.winfo_screenheight() // 2 - 730 // 2)) root.update() root.title('课程表') root.resizable(0, 0) root.overrideredirect(1) root.grid_columnconfigure(0, weight=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() for i in range(1, len(listindes)): if listindes[i] == '上操': zxs = tkinter.Label(root, image=sport_photo, font=('华文行楷', 40)) elif listindes[i] == '眼操': zxs = tkinter.Label(root, image=eye_photo, font=('华文行楷', 40)) elif listindes[i] == '吃饭': zxs = tkinter.Label(root, image=line_photo, font=('华文行楷', 40)) elif listindes[i] == '升旗': zxs = tkinter.Label(root, image=flag_photo, font=('华文行楷', 40)) elif '/' not in listindes[i]: zxs = tkinter.Label(root, text=listindes[i][0], font=('华文行楷', 40)) else: zxs = tkinter.Label(root, text=listindes[i], font=('华文行楷', 20)) zxs.grid(column=0, row=i) root.update() 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.grid(row=0, column=0, ipadx=0, sticky=W) 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), bg='#4472c4', activebackground='#4472c4', fg='white') 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 ''' wait_window = tkinter.Toplevel(root) b1 = tkinter.Scrollbar(wait_window, width=40) b1.place(relx=0.5,rely=0.5,anchor='center') b2 = tkinter.Listbox(wait_window, yscrollcommand=b1.set,width=500,height=600) with open('support/report.txt', 'r+') as f: for x in f.readlines(): b2.insert(tkinter.END, x) b2.place(relx=0.5,rely=0.5,anchor='center') b1.config(command=b2.yview) win_width = 1000 win_height = 500 win_x = root.winfo_screenwidth() // 2 - win_width // 2 win_y = root.winfo_screenheight() // 2 - win_height // 2 # 窗口垂直居中 wait_window.geometry('{}x{}+{}+{}'.format(win_width, win_height, win_x, win_y)) pp = tkinter.Button(wait_window, text="确定", command=wait_window.destroy) pp.place(relx=0.5,rely=1,anchor='s') wait_window.wait_window() ''' 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() try: if ('Windows 任务管理器' in windows) or ('任务管理器' in windows) or ('Windows任务管理器' in windows): try: window = pygetwindow.getWindowsWithTitle('任务管理器')[0] except Exception as e: log(str(e) + 'line 849', 'error') except Exception as e: log(str(e) + 'line 874', 'error') '''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(): global ve ve = False def chan(): global ve ve = False def clo(event): tsk.destroy() tkinter.messagebox.showinfo('提示', '解除限制,有效期180秒') root.after(180000, lambda: chan()) def alt_f4(event): global pressed_f4 pressed_f4 = True while 1: if not rest(): windows = pygetwindow.getAllTitles() try: tsk.overrideredirect(1) tsk.wm_attributes('-topmost', 1) except: pass if (('任务管理器' in windows) or ('Windows 任务管理器' in windows)) and ve == False: time.sleep(1) window = pygetwindow.getWindowsWithTitle('任务管理器')[0] tsk = tkinter.Toplevel() tsk.overrideredirect(1) tsk.wm_attributes('-topmost', 1) leb = tkinter.Label(tsk, text='禁止使用任务管理器,请等待解决。', font=('仿宋', 24)) leb.place(relx=0.5, rely=0.8, anchor='center') ph = tkinter.Label(tsk, image=lock_photo, font=('仿宋', 24)) ph.place(relx=0.5, rely=0.5, anchor='center') ve = True tsk.geometry('{}x{}+{}+{}'.format(tsk.winfo_screenwidth(), tsk.winfo_screenheight(), 0, 0)) tsk.bind('', clo) tsk.bind('', alt_f4) if '成绩单' in windows: pygetwindow.getWindowsWithTitle('成绩单')[0].close() time.sleep(0.3) else: time.sleep(check_resttime()) ''' 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') ''' 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() ''' def verify_password(pwd): if pwd=='xinshijie2002': toplevels.destroy() time.sleep(5000) while 1: while not rest(): time.sleep(1) if t4.isAlive(): pass else: def do_exit(): global pressed_f4 if pressed_f4: # Deny if Alt-F4 is pressed pressed_f4 = False # Reset variable def alt_f4(event): # Alt-F4 is pressed global pressed_f4 pressed_f4 = True toplevels = tkinter.Tk() toplevels.geometry('{}x{}+{}+{}'.format(toplevels.winfo_screenwidth(), toplevels.winfo_screenheight(),0,0)) toplevels.resizable(0, 0) toplevels.overrideredirect(1) toplevels.wm_attributes('-topmost', 1) toplevels.protocol("WM_DELETE_WINDOW") toplevels.bind('', alt_f4) toplevels.protocol("WM_DELETE_WINDOW", do_exit) toplevels.configure(bg='white') tkinter.Message(toplevels, text='正在等待被关闭的模块启动', font=('宋体', 30)).place(relx=0.5,rely=0.5,anchor='center') toplevels.update() try: t4.start() except Exception as e: tkinter.Message(toplevels, text='没有启动成功,请等待解决。'+str(e), font=('宋体', 30)).place(relx=0.5, rely=0.5, anchor='center') ent=tkinter.Entry(toplevels,width=60,show='·') ent.place(relx=0.5,rely=0.7,anchor='center') btn = tkinter.Button(toplevels,text='确定',command=lambda :verify_password(ent.get()) ,width=60) btn.place(relx=0.5, rely=0.8, anchor='center') toplevels.mainloop() else: time.sleep(check_resttime()) '''