2072 lines
75 KiB
Python
2072 lines
75 KiB
Python
from threading import Thread
|
||
from tkinter import *
|
||
from arcade import load_sound, play_sound, stop_sound
|
||
from tkinter import font
|
||
import tkinter.filedialog
|
||
import random, tkinter, time, xlrd, datetime, logging, hashlib, os, shutil, pyperclip, requests, threading
|
||
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, \
|
||
style, \
|
||
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, \
|
||
lock_photo, \
|
||
countdown_photo, \
|
||
sport_photo, \
|
||
eye_photo, \
|
||
line_photo, \
|
||
flag_photo, \
|
||
pen_photo, \
|
||
tick_photo, \
|
||
choice_photo, \
|
||
image_dict, \
|
||
screen_height
|
||
fin = False
|
||
style = Style(theme="newtheme")
|
||
root = style.master
|
||
style.configure("TButton")
|
||
DraggableWindow(root)
|
||
screen_width = root.winfo_screenwidth()
|
||
screen_height = root.winfo_screenheight()
|
||
root.resizable(0, 0)
|
||
root.overrideredirect(1)
|
||
for x in range(75):
|
||
win_width = (4 * x) + 201
|
||
win_height = (4 * x) + 2
|
||
win_x = screen_width // 2 - win_width // 2
|
||
win_y = screen_height // 2 - win_height // 2 # 窗口垂直居中
|
||
root.geometry("{}x{}+{}+{}".format(win_width, win_height, win_x, win_y))
|
||
root.update()
|
||
root.update()
|
||
log("正在清理文件", "info")
|
||
while fin == False:
|
||
c = tkinter.Label(text=ll, font=("宋体", 10))
|
||
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(1500)
|
||
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)
|
||
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)
|
||
choiced = Image.open("support/choice.png")
|
||
choiced = choiced.resize((40, 40))
|
||
choice_photo = ImageTk.PhotoImage(choiced)
|
||
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 # 将文件名作为键,图片对象作为值存储在字典中
|
||
)
|
||
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(True)
|
||
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("<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):
|
||
# 如果触发事件的控件是Button或Text,就不开始移动窗口
|
||
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):
|
||
# 如果触发事件的控件是Button或Text,就不移动窗口
|
||
if (
|
||
isinstance(event.widget, tkinter.Button)
|
||
or isinstance(event.widget, tkinter.Text)
|
||
or isinstance(event.widget, tkinter.Entry)
|
||
or nodrag == True
|
||
):
|
||
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,
|
||
)
|
||
|
||
|
||
class PILFilter(logging.Filter):
|
||
def filter(self, record):
|
||
return record.name != "PIL" or record.levelno > logging.DEBUG
|
||
|
||
|
||
handler = logging.StreamHandler()
|
||
handler.addFilter(PILFilter())
|
||
|
||
# 设置日志级别和处理器
|
||
logging.basicConfig(level=logging.DEBUG, handlers=[handler])
|
||
|
||
|
||
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") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index("时刻表") # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
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") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index(
|
||
zhou[d.weekday()]
|
||
) # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
try:
|
||
ax = 1
|
||
while (
|
||
listindes[x + ax] == "升旗"
|
||
or listindes[x + ax] == "上操"
|
||
or listindes[x + ax] == "吃饭"
|
||
or listindes[x + ax] == "眼操"
|
||
):
|
||
ax += 1
|
||
return listindes[x], listindes[x + ax]
|
||
except:
|
||
return listindes[x]
|
||
return False
|
||
except:
|
||
return False
|
||
|
||
|
||
def rest():
|
||
try:
|
||
excel = xlrd.open_workbook("support/时间表.xls") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index("时间表") # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
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
|
||
|
||
|
||
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),
|
||
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() - (screen_width // 2 - 500 / 2)) / speed
|
||
step_y = (root.winfo_y() - (screen_height // 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(screen_width // 2 - 500 / 2),
|
||
int(screen_height // 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 reset_grid_configurations(root):
|
||
for row in range(20):
|
||
root.grid_rowconfigure(row, weight=0, minsize=0)
|
||
for col in range(5):
|
||
root.grid_columnconfigure(col, weight=0, minsize=0)
|
||
|
||
|
||
def check_homework():
|
||
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)
|
||
if "——" in x:
|
||
copylist = copylist + x.split("——")[1]
|
||
else:
|
||
copylist = copylist + str(l) + ")" + x
|
||
l = l + 1
|
||
return copylist
|
||
|
||
|
||
def homework(pas=None, window=None, line=9999):
|
||
global z, toplevel, back_photo, speed
|
||
z = True
|
||
if window == lo:
|
||
for child in root.grid_slaves():
|
||
cc = child.grid_info()
|
||
if cc["column"] == 1 and cc["row"] == line - 1:
|
||
child.grid_remove()
|
||
zxs = tkinter.Label(root, text=pas[0], font=("华文行楷", 40))
|
||
zxs.grid(column=1, row=line - 1)
|
||
reset_grid_configurations(window)
|
||
style.configure("TButton", font=("微软雅黑", 10))
|
||
if window != root:
|
||
window.configure(width=300)
|
||
|
||
def ex():
|
||
if window == lo:
|
||
schedule("fromhomework")
|
||
else:
|
||
for child in right_area.grid_slaves():
|
||
child.grid_remove()
|
||
for t in right_area.place_slaves():
|
||
t.destroy()
|
||
schedule_for_view()
|
||
right_area.configure(width=55)
|
||
|
||
def schedule_for_view():
|
||
global right_area
|
||
for btn in right_area.place_slaves():
|
||
btn.destroy()
|
||
for btn in right_area.grid_slaves():
|
||
btn.grid_remove()
|
||
right_area.grid_columnconfigure(0, weight=1)
|
||
right_area.grid_propagate(False)
|
||
try:
|
||
excel = xlrd.open_workbook("support/课程表.xls") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index(
|
||
zhou[d.weekday()]
|
||
) # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
except:
|
||
listindes = "没有找到课程表文件"
|
||
log("课程表文件不存在", "error")
|
||
# 遍历该列所有的内容
|
||
zxs = tkinter.Label(right_area, text="曾", font=("华文行楷", 40))
|
||
zxs.grid(column=0, row=0)
|
||
window.update()
|
||
he = zxs.winfo_height()
|
||
wi = zxs.winfo_width()
|
||
zxs.destroy()
|
||
style.configure("TButton", font=("华文行楷", 40))
|
||
for i in range(1, len(listindes)):
|
||
if listindes[i] == "上操":
|
||
zxs = tkinter.Label(
|
||
right_area, image=sport_photo, font=("华文行楷", 40)
|
||
)
|
||
elif listindes[i] == "眼操":
|
||
zxs = tkinter.Label(right_area, image=eye_photo, font=("华文行楷", 40))
|
||
elif listindes[i] == "吃饭":
|
||
zxs = tkinter.Label(right_area, image=line_photo, font=("华文行楷", 40))
|
||
elif listindes[i] == "升旗":
|
||
zxs = tkinter.Label(right_area, image=flag_photo, font=("华文行楷", 40))
|
||
elif "/" not in listindes[i]:
|
||
window.grid_rowconfigure(i - 1, weight=1)
|
||
zxs = tkinter.Frame(right_area, height=he, width=wi)
|
||
ttk.Button(
|
||
zxs,
|
||
text=listindes[i][0],
|
||
command=lambda listindes=listindes[i], g=i: homework(
|
||
pas=listindes, window=right_area, line=g
|
||
),
|
||
style="light.TButton",
|
||
).place(
|
||
relx=0.5, rely=0.5, anchor="center"
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
else:
|
||
zxs = tkinter.Label(
|
||
right_area, text=listindes[i], font=("华文行楷", 20)
|
||
)
|
||
zxs.grid(column=0, row=i)
|
||
right_area.grid_rowconfigure(i, weight=1)
|
||
window.update()
|
||
listindes.clear()
|
||
|
||
def edit(con):
|
||
for child in too.grid_slaves():
|
||
child.grid_remove()
|
||
for t in too.place_slaves():
|
||
t.destroy()
|
||
|
||
ppp = tkinter.Text(too, font=("黑体", 24))
|
||
window.update()
|
||
co = tkinter.Text(too, width=ppp.cget("width"), font=("黑体", 36))
|
||
co.focus_set()
|
||
co.insert("insert", con)
|
||
co.grid(row=0, column=0, sticky="nsew")
|
||
button = tkinter.Button(
|
||
too, image=tick_photo, command=lambda: pasd(co.get(1.0, END).strip())
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
button.place(rely=0, relx=0.5, anchor="n")
|
||
window.update()
|
||
|
||
def look():
|
||
global cross_photo
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.place_slaves():
|
||
t.destroy()
|
||
|
||
def secure():
|
||
pasd("")
|
||
|
||
secure()
|
||
|
||
def pasd(copylist):
|
||
global too, right_area, nodrag
|
||
nodrag = True
|
||
if copylist == "" or copylist == "refresh":
|
||
if copylist == "":
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.place_slaves():
|
||
t.destroy()
|
||
step_wid = (screen_width - window.winfo_width()) / speed
|
||
step_hei = (screen_height - window.winfo_height()) / speed
|
||
step_x = (window.winfo_x() - 0) / speed
|
||
step_y = (window.winfo_y() - 0) / speed
|
||
wid = window.winfo_width()
|
||
hei = window.winfo_height()
|
||
xxx = window.winfo_x()
|
||
yyy = window.winfo_y()
|
||
# 移动窗口到指定位置,并有动画效果
|
||
for x in range(speed):
|
||
wid = wid + step_wid
|
||
hei = hei + step_hei
|
||
xxx = xxx - step_x
|
||
yyy = yyy - step_y
|
||
window.geometry(
|
||
"{}x{}+{}+{}".format(int(wid), int(hei), int(xxx), int(yyy))
|
||
)
|
||
window.update()
|
||
window.geometry("{}x{}+{}+{}".format(screen_width, screen_height, 0, 0))
|
||
window.grid_rowconfigure(0, weight=1)
|
||
too = tkinter.Frame(window)
|
||
too.grid(column=0, row=0, sticky="nsew")
|
||
right_area = tkinter.Frame(window, height=screen_height)
|
||
right_area.grid(row=0, column=1, sticky="nsew")
|
||
window.grid_rowconfigure(0, weight=1) # too 所在的列
|
||
window.grid_columnconfigure(0, weight=1) # too 所在的列
|
||
window.grid_columnconfigure(
|
||
1, minsize=55, weight=0
|
||
) # right_area 所在的列,固定宽度
|
||
right_area.configure(width=55)
|
||
schedule_for_view()
|
||
elif copylist == "refresh":
|
||
for child in too.grid_slaves():
|
||
child.grid_remove()
|
||
for t in too.place_slaves():
|
||
t.destroy()
|
||
copylist = check_homework()
|
||
pyperclip.copy(str(d.date()) + "\n" + copylist)
|
||
doc = Document()
|
||
# 这里相当于输入了一个空格,后面等待着文字输入
|
||
paragraph3 = doc.add_paragraph()
|
||
paragraph3.add_run("请勿在此处更改,不会被保存。\n" + copylist)
|
||
try:
|
||
doc.save("support/" + str(d.date()) + "作业.docx")
|
||
except:
|
||
on_button_click("请将word窗口关闭", "")
|
||
window.update()
|
||
else:
|
||
for child in too.grid_slaves():
|
||
child.grid_remove()
|
||
for t in too.place_slaves():
|
||
t.destroy()
|
||
tkinter.Label(
|
||
too,
|
||
text=" ",
|
||
font=("黑体", 24),
|
||
wraplength=root.winfo_width(),
|
||
).grid(column=0, row=0, sticky="nsew")
|
||
root.update()
|
||
ly = tkinter.Label(
|
||
too,
|
||
text=str(d.date()) + " " + zhou[d.weekday()],
|
||
font=("黑体", 24),
|
||
wraplength=root.winfo_width(),
|
||
)
|
||
ly.grid(column=0, row=0, sticky="nsew")
|
||
root.update()
|
||
lp = tkinter.Label(
|
||
too,
|
||
text=copylist,
|
||
font=("黑体", 36),
|
||
anchor="w",
|
||
justify="left",
|
||
wraplength=root.winfo_width() - 55,
|
||
)
|
||
lp.grid(column=0, row=1, ipadx=50, sticky="nsew")
|
||
adjust_font_size(lp, max_height=root.winfo_height() - ly.winfo_height())
|
||
zzz = tkinter.Frame(too)
|
||
lz = tkinter.Button(zzz, text="→←", command=lambda: schedule("fromhomework"))
|
||
lz.grid(column=0, row=0, sticky="nsew")
|
||
lf = tkinter.Button(zzz, text="复制", command=lambda: copy(zzz))
|
||
lf.grid(column=1, row=0, sticky="nsew")
|
||
li = tkinter.Button(zzz, image=pen_photo, command=lambda: edit(copylist))
|
||
li.grid(column=2, row=0, sticky="nsew")
|
||
zzz.grid(column=0, row=2, sticky="nsew")
|
||
zzz.grid_columnconfigure(0, weight=1) # too 所在的列
|
||
zzz.grid_columnconfigure(1, weight=1) # too 所在的列
|
||
zzz.grid_columnconfigure(2, weight=1) # too 所在的列
|
||
too.grid_rowconfigure(1, weight=1) # too 所在的列
|
||
window.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 window.grid_slaves():
|
||
if child.grid_info()["row"] == line:
|
||
child.grid_remove()
|
||
ppp = tkinter.Text(
|
||
window,
|
||
height=2,
|
||
)
|
||
ppp.focus_set()
|
||
ppp.insert("insert", subject)
|
||
ppp.bind("<Key>", handle_return)
|
||
ppp.grid(row=line, column=0, ipadx=30, padx=10)
|
||
button = tkinter.Button(
|
||
window,
|
||
image=tick_photo,
|
||
command=lambda: rewrite_homework(
|
||
sub, subject, book, ppp.get(1.0, END).strip()
|
||
),
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
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()
|
||
# 遍历每一行,检查是否有内容为”123“的行
|
||
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)
|
||
if window != lo:
|
||
pasd("refresh")
|
||
add_work(sub, book)
|
||
|
||
def add_work_write(sub, book, info):
|
||
with open("support/homework/" + str(d.date()) + sub, "a+") as f:
|
||
f.write(book + info + "\n")
|
||
pass
|
||
try:
|
||
window.update()
|
||
add_work(sub, book)
|
||
except:
|
||
pass
|
||
if window != lo:
|
||
pasd("refresh")
|
||
|
||
def delete_homework(sub, subject, book):
|
||
with open("support/homework/" + str(d.date()) + sub, "r") as file:
|
||
lines = file.readlines()
|
||
|
||
# 遍历每一行,检查是否有内容为”123“的行
|
||
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)
|
||
if window != lo:
|
||
pasd("refresh")
|
||
add_work(sub, book)
|
||
|
||
def handle_return(event):
|
||
if event.keysym == "Return":
|
||
homework_input_box.insert(END, "\n——")
|
||
return "break"
|
||
|
||
def add_work(sub, book):
|
||
window.grid_columnconfigure(0, weight=1)
|
||
global cross_photo
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.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(
|
||
window, text=subject, justify="left", wraplength=160
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
button.grid(
|
||
row=i + 1, column=0, ipadx=50, pady=5, sticky="w"
|
||
) # 假设你只使用一列
|
||
button = tkinter.Button(
|
||
window,
|
||
image=pen_photo,
|
||
command=lambda subject=subject, i=i + 1: edit_homework(
|
||
sub, subject, book, i
|
||
),
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
button.grid(row=i + 1, column=1, ipadx=1, pady=5) # 假设你只使用一列
|
||
button = tkinter.Button(
|
||
window,
|
||
image=cross_photo,
|
||
command=lambda subject=subject: delete_homework(sub, subject, book),
|
||
bg="#4472c4",
|
||
activebackground="#4472c4",
|
||
fg="white",
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
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 window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.place_slaves():
|
||
t.destroy()
|
||
leb = tkinter.Message(
|
||
window,
|
||
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, homework_input_box.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(window, image=back_photo, command=lambda: confirm()choice_book(sub),bg='#4472c4',activebackground='#4472c4',fg='white').place(relx=0, rely=0,anchor='nw')
|
||
tkinter.Button(
|
||
window,
|
||
image=back_photo,
|
||
command=lambda: confirm(
|
||
sub, book, homework_input_box.get(1.0, END).strip()
|
||
),
|
||
bg="#4472c4",
|
||
activebackground="#4472c4",
|
||
fg="white",
|
||
).place(relx=0, rely=0, anchor="nw")
|
||
tkinter.Label(
|
||
window, text=sub + " " + book + "\n" + "请输入具体页数或题号"
|
||
).grid(row=0, column=0, ipadx=15, pady=10, columnspan=3)
|
||
global homework_input_box
|
||
homework_input_box = tkinter.Text(
|
||
window,
|
||
height=20,
|
||
)
|
||
homework_input_box.focus_set()
|
||
homework_input_box.bind("<Key>", handle_return)
|
||
homework_input_box.grid(
|
||
row=i + 2, column=0, columnspan=3, sticky="nsew", padx=10
|
||
)
|
||
ttk.Button(
|
||
window,
|
||
image=continued_photo,
|
||
command=lambda: add_work_write(
|
||
sub, book, homework_input_box.get(1.0, END).strip()
|
||
),
|
||
style="light.TButton",
|
||
).grid(row=i + 4, column=0, ipadx=15, pady=10)
|
||
# tkinter.Button(window, text='回车可用(点此阅读回车说明)',command=lambda :tkinter.messagebox.showinfo('回车使用方法','按下回车后自动在下一行添加破折号“——”,破折号不会在最终页面中显示,仅代表新一行仍属于本项作业,不会被标号。\n如果手动删除某行的破折号,则该行将被认为是新一项作业,并顺序标号。\n可手动添加破折号,代表该行不会被标号。')).grid(row=i+3, column=0, ipadx=15, pady=10, columnspan=3)
|
||
tkinter.Button(window, image=cross_photo, command=lambda: ex()).place(
|
||
relx=1, rely=0, anchor="ne"
|
||
)
|
||
|
||
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 window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.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(
|
||
window,
|
||
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(
|
||
window,
|
||
text=subject,
|
||
command=lambda subject=subject: add_work(sub, subject),
|
||
height=3,
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
button.grid(
|
||
row=i // 2 + 1, column=i % 2, pady=10, padx=10, sticky="nsew"
|
||
) # 假设你只使用一列
|
||
tkinter.Button(
|
||
window, image=back_photo, command=lambda: choice_subject()
|
||
).place(relx=0, rely=0, anchor="nw")
|
||
ppp = tkinter.Entry(window, width=10)
|
||
ppp.grid(row=i + 2, column=0, ipadx=15, columnspan=3)
|
||
ttk.Button(
|
||
window,
|
||
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(
|
||
window,
|
||
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(window, image=cross_photo, command=lambda: ex()).place(
|
||
relx=1, rely=0, anchor="ne"
|
||
)
|
||
window.update()
|
||
pass
|
||
|
||
def window_close_handle():
|
||
global z, toplevel
|
||
z = False
|
||
window.destroy()
|
||
try:
|
||
toplevel.overrideredirect(1)
|
||
except:
|
||
pass
|
||
|
||
for x in window.place_slaves():
|
||
x.place_forget()
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
if window == root:
|
||
window.protocol("WM_DELETE_WINDOW", window_close_handle)
|
||
root.update()
|
||
|
||
def the():
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.place_slaves():
|
||
t.destroy()
|
||
tkinter.Button(window, image=cross_photo, command=lambda: ex()).place(
|
||
relx=1, rely=0, anchor="ne"
|
||
)
|
||
tkinter.Button(
|
||
window, image=back_photo, command=lambda: choice_subject()
|
||
).place(relx=0, rely=0, anchor="nw")
|
||
tkinter.Label(window, text="\n\n名称").grid(column=0, row=0)
|
||
tkinter.Label(window, text="\n\n存活").grid(column=1, row=0)
|
||
tkinter.Label(window, text="\n\n目标").grid(column=2, row=0)
|
||
tkinter.Label(window, text="\n\n操作").grid(column=3, row=0)
|
||
a = 2
|
||
for thread in threading.enumerate():
|
||
tkinter.Label(window, text=thread.getName()).grid(column=0, row=a)
|
||
tkinter.Label(window, text=thread.is_alive()).grid(column=1, row=a)
|
||
# 检查线程是否有 target 属性,并获取其名称(而不是尝试调用它)
|
||
if hasattr(thread, "target"):
|
||
target_name = (
|
||
thread.target.__name__
|
||
if callable(thread.target)
|
||
else str(thread.target)
|
||
)
|
||
target_label = tkinter.Label(window, text=target_name)
|
||
else:
|
||
target_label = tkinter.Label(
|
||
window, text="None"
|
||
) # 对于没有 target 的线程,显示 "None"
|
||
|
||
target_label.grid(column=2, row=a)
|
||
if thread.is_alive():
|
||
tkinter.Button(
|
||
window,
|
||
text="停止",
|
||
command=lambda: tkinter.messagebox.showwarning(
|
||
"", "暂不支持此功能"
|
||
),
|
||
).grid(column=3, row=a)
|
||
else:
|
||
try:
|
||
tkinter.Button(
|
||
window,
|
||
text="启动",
|
||
command=lambda: tkinter.messagebox.showwarning(
|
||
"", "暂不支持此功能"
|
||
),
|
||
).grid(column=3, row=a)
|
||
except Exception as e:
|
||
tkinter.messagebox.showwarning("", str(e))
|
||
a = a + 1
|
||
tkinter.Label(window, text="v24.10.28 ©曾祥盛").grid(
|
||
column=0, row=a + 1, columnspan=4
|
||
)
|
||
|
||
def choice_subject(sub=None):
|
||
window.grid_rowconfigure(1, weight=0)
|
||
window.grid_columnconfigure(0, weight=1)
|
||
window.grid_columnconfigure(1, weight=1)
|
||
window.grid_columnconfigure(2, weight=0)
|
||
global z
|
||
for child in window.grid_slaves():
|
||
child.grid_remove()
|
||
for t in window.place_slaves():
|
||
t.destroy()
|
||
subjects = (
|
||
open("support/subjects", "r").read().splitlines()
|
||
) # 读取文件并分割成行
|
||
tkinter.Label(window, text="请选择科目").grid(
|
||
row=0, column=0, pady=10, columnspan=2, sticky="nsew"
|
||
)
|
||
for i, subject in enumerate(subjects):
|
||
try:
|
||
button = ttk.Button(
|
||
window,
|
||
image=image_dict[subject],
|
||
compound="left",
|
||
text=subject,
|
||
command=lambda subject=subject: choice_book(subject),
|
||
style="light.TButton",
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
except:
|
||
button = ttk.Button(
|
||
window,
|
||
image=up_photo,
|
||
compound="left",
|
||
text=subject,
|
||
command=lambda subject=subject: choice_book(subject),
|
||
style="light.TButton",
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
button.grid(
|
||
row=i // 2 + 1, column=i % 2, sticky="nsew", ipady=20
|
||
) # 假设你只使用一列
|
||
ppp = tkinter.Entry(window, width=10)
|
||
ppp.grid(row=i + 2, column=0, ipadx=15, columnspan=2)
|
||
ttk.Button(
|
||
window,
|
||
image=continued_photo,
|
||
command=lambda: add_subject(ppp.get()),
|
||
style="light.TButton",
|
||
).grid(row=i + 3, column=0, pady=10, columnspan=2)
|
||
tkinter.Button(window, image=cross_photo, command=lambda: ex()).place(
|
||
relx=1, rely=0, anchor="ne"
|
||
)
|
||
tkinter.Button(window, text="thread", command=lambda: the()).place(
|
||
relx=0, rely=1, anchor="sw"
|
||
)
|
||
if sub != None:
|
||
if sub in subjects:
|
||
choice_book(sub)
|
||
window.update()
|
||
|
||
if pas == True:
|
||
pasd("")
|
||
elif pas != None:
|
||
choice_subject(pas)
|
||
else:
|
||
choice_subject()
|
||
|
||
|
||
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()
|
||
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 = screen_height // 2 - win_height // 2 # 窗口垂直居中
|
||
step_x = ((screen_width - win_width) - root.winfo_x()) / speed
|
||
step_y = ((screen_height // 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"), font=("微软雅黑", 10)
|
||
)
|
||
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")
|
||
# set = tkinter.Button(text='设置', command=lambda: settings(),bg='#4472c4',activebackground='#4472c4',fg='white')
|
||
# set.place(relx=0.5, rely=0, anchor='n')
|
||
root.update()
|
||
inn = tkinter.Label(text="正在处理……", font=("微软雅黑", 10))
|
||
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:
|
||
with open("support/1.txt", "r") as f:
|
||
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现在处于下课时间,抽到的人将不会添加到已抽中列表。",
|
||
font=("微软雅黑", 10),
|
||
)
|
||
elif str(nolis.get()) == "1":
|
||
inf = tkinter.Label(
|
||
text="当前有"
|
||
+ info
|
||
+ "人。已忽略已抽中列表。\n抽到的人将不会添加到已抽中列表。",
|
||
font=("微软雅黑", 10),
|
||
)
|
||
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=str(len(chosed)) + "/" + info + "。剩余5人时将开启新一轮。",
|
||
font=("微软雅黑", 10),
|
||
)
|
||
inf.place(relx=0.5, rely=0.7, anchor="center")
|
||
start = tkinter.Button(
|
||
text=status,
|
||
command=lambda: main(),
|
||
font=("宋体", 24),
|
||
width=30,
|
||
bg="#4472c4",
|
||
activebackground="#4472c4",
|
||
fg="white",
|
||
)
|
||
start.place(relx=0.5, rely=1, anchor="s")
|
||
|
||
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=30,
|
||
bg="#4472c4",
|
||
activebackground="#4472c4",
|
||
fg="white",
|
||
)
|
||
start.place(relx=0.5, rely=1, anchor="s")
|
||
while not flag:
|
||
r = random.randint(0, len(list) - 1)
|
||
if len(chosed) == len(list) - 5:
|
||
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.4, 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.4, 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.4, anchor="center")
|
||
start = tkinter.Button(
|
||
text=status,
|
||
command=lambda: main(),
|
||
font=("宋体", 24),
|
||
width=30,
|
||
bg="#4472c4",
|
||
activebackground="#4472c4",
|
||
fg="white",
|
||
)
|
||
start.place(relx=0.5, rely=1, anchor="s")
|
||
|
||
|
||
def adjust_font_size(label, max_width=None, max_height=None, min_size=1):
|
||
# 获取当前内容
|
||
text = label.cget("text")
|
||
|
||
# 初始字体大小(可以根据需要调整)
|
||
font_size = 48
|
||
|
||
# 尝试从当前字体描述中提取字体家族(如果不存在,则使用默认家族)
|
||
try:
|
||
# 注意:这里的解析是简化的,可能不适用于所有情况
|
||
# 正确的做法是使用更健壮的解析方法,或者保存原始Font对象(如果可能的话)
|
||
current_font_desc = label.cget("font")
|
||
family = current_font_desc.split()[0] if current_font_desc else "Arial"
|
||
except:
|
||
family = "Arial" # 默认字体家族
|
||
|
||
# 创建字体对象(使用默认或提取的家族)
|
||
current_font = font.Font(family=family, size=font_size)
|
||
|
||
# 获取 Label 的实际宽高(如果提供了max_width和max_height,则使用它们)
|
||
label_width = max_width if max_width else label.winfo_width()
|
||
label_height = max_height if max_height else label.winfo_height()
|
||
|
||
# 不断缩小字体大小直到内容完全显示或达到最小字体大小
|
||
while True:
|
||
# 设置新的字体大小
|
||
current_font.configure(size=font_size)
|
||
|
||
# 更新 Label 字体
|
||
label.config(font=current_font)
|
||
|
||
# 更新窗口以应用新的字体大小并获取实际内容所需的宽高
|
||
label.update_idletasks()
|
||
|
||
# 获取 Label 实际内容所需的宽高(考虑wraplength和padding等可能影响的因素)
|
||
# 注意:wraplength可能会限制宽度,但不影响字体大小的调整逻辑
|
||
text_width = label.winfo_reqwidth()
|
||
text_height = label.winfo_reqheight()
|
||
# 判断是否满足条件
|
||
if (max_width is None or text_width <= label_width) and (
|
||
max_height is None or text_height <= label_height
|
||
):
|
||
break
|
||
|
||
# 字体大小递减(避免无限循环)
|
||
font_size -= 1
|
||
# 检查是否已达到最小字体大小
|
||
if font_size < min_size:
|
||
label.config(text="字数过多")
|
||
font_size = 48
|
||
|
||
|
||
def copy(lg):
|
||
pyperclip.copy(str(d.date()) + "\n" + check_homework())
|
||
lf = tkinter.Button(lg, image=tick_photo)
|
||
lf.grid(column=1, row=0, sticky="nsew")
|
||
root.after(5000, lambda: lf.destroy())
|
||
|
||
|
||
def schedule(fr):
|
||
global \
|
||
thu, \
|
||
other, \
|
||
zhou, \
|
||
d, \
|
||
canceltopping, \
|
||
photo, \
|
||
lose, \
|
||
hh, \
|
||
h, \
|
||
no, \
|
||
z, \
|
||
speed, \
|
||
nodrag, \
|
||
top, \
|
||
btn, \
|
||
lo
|
||
root.wm_attributes("-topmost", 0)
|
||
nodrag = False
|
||
z = False
|
||
for btn in root.place_slaves():
|
||
btn.destroy()
|
||
for btn in root.grid_slaves():
|
||
btn.grid_remove()
|
||
reset_grid_configurations(root)
|
||
if lose == []:
|
||
pass
|
||
else:
|
||
a = "缺少关键组件:\n"
|
||
for x in lose:
|
||
a = a + x + "\n"
|
||
on_button_click(a, "")
|
||
lose = []
|
||
if 1:
|
||
step_wid = (359 - root.winfo_width()) / speed
|
||
step_hei = (800 - root.winfo_height()) / speed
|
||
step_x = (root.winfo_x() - (screen_width - 359)) / speed
|
||
step_y = (root.winfo_y() - 0) / speed
|
||
wid = root.winfo_width()
|
||
hei = root.winfo_height()
|
||
xxx = root.winfo_x()
|
||
yyy = root.winfo_y()
|
||
# 移动窗口到指定位置,并有动画效果
|
||
for x in range(speed):
|
||
wid = wid + step_wid
|
||
hei = hei + step_hei
|
||
xxx = xxx - step_x
|
||
yyy = yyy - step_y
|
||
root.geometry("{}x{}+{}+{}".format(int(wid), int(hei), int(xxx), int(yyy)))
|
||
root.update()
|
||
root.geometry("{}x{}+{}+{}".format(359, 800, screen_width - 359, 0))
|
||
root.update()
|
||
root.title("课程表")
|
||
root.resizable(0, 0)
|
||
root.overrideredirect(1)
|
||
try:
|
||
excel = xlrd.open_workbook("support/课程表.xls") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index(
|
||
zhou[d.weekday()]
|
||
) # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
except:
|
||
on_button_click("请确认课程表文件\n存在且格式正确", "")
|
||
log("课程表文件不存在", "error")
|
||
root.quit()
|
||
# 遍历该列所有的内容
|
||
style.configure("TButton", font=("华文行楷", 40))
|
||
zxs = tkinter.Label(root, text="曾", font=("华文行楷", 40))
|
||
zxs.grid(column=1, row=0)
|
||
root.update()
|
||
he = zxs.winfo_height()
|
||
wi = zxs.winfo_width()
|
||
zxs.destroy()
|
||
lo = tkinter.Frame(root, width=300)
|
||
lo.grid_propagate(False)
|
||
# 使用配置好的样式创建按钮
|
||
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]:
|
||
root.grid_rowconfigure(i - 1, weight=1)
|
||
zxs = tkinter.Frame(root, height=he, width=wi)
|
||
ttk.Button(
|
||
zxs,
|
||
text=listindes[i][0],
|
||
command=lambda listindes=listindes[i], g=i: homework(
|
||
pas=listindes, window=lo, line=g
|
||
),
|
||
style="light.TButton",
|
||
).place(
|
||
relx=0.5, rely=0.5, anchor="center"
|
||
) # 使用 lambda 函数打印按钮的文本
|
||
else:
|
||
zxs = tkinter.Label(root, text=listindes[i], font=("华文行楷", 20))
|
||
zxs.grid(column=1, row=i - 1)
|
||
root.update()
|
||
listindes.clear()
|
||
y = tkinter.Button(text=zhou[d.weekday()], command=lambda: choice("fromtab"))
|
||
y.grid(row=i, column=1, sticky="nsew")
|
||
global h, labeled
|
||
root.grid_columnconfigure(0, weight=1)
|
||
lw = tkinter.Label(lo, text=str(d.date()), font=("微软雅黑", 20))
|
||
lw.grid(column=0, row=0, sticky="nsew")
|
||
root.update()
|
||
lo.grid(column=0, row=0, rowspan=i, sticky="nsew")
|
||
lj = tkinter.Label(
|
||
lo,
|
||
text=check_homework(),
|
||
wraplength=root.winfo_width() - y.winfo_width(),
|
||
font=("黑体", 20),
|
||
justify="left",
|
||
)
|
||
lj.grid(column=0, row=1, sticky="nsew")
|
||
zzz = tkinter.Frame(root)
|
||
zzz.grid(column=0, row=i, sticky="nsew")
|
||
zzz.grid_columnconfigure(0, weight=1)
|
||
zzz.grid_columnconfigure(1, weight=1)
|
||
if fr != "fromhomework":
|
||
top = tkinter.Toplevel()
|
||
top.resizable(False, False)
|
||
top.overrideredirect(True)
|
||
top.wm_attributes("-topmost", 1)
|
||
try:
|
||
if type(check_class()) == tuple:
|
||
btn = tkinter.Button(
|
||
top,
|
||
text=check_class()[0][0] + "→" + check_class()[1][0],
|
||
command=lambda: choice("fromtab"),
|
||
font=("华文行楷", 20),
|
||
)
|
||
else:
|
||
btn = tkinter.Button(
|
||
top,
|
||
text=check_class(),
|
||
command=lambda: choice("fromtab"),
|
||
font=("华文行楷", 20),
|
||
)
|
||
except TypeError:
|
||
try:
|
||
btn = tkinter.Button(
|
||
top,
|
||
text=check_class()[0][0],
|
||
command=lambda: choice("fromtab"),
|
||
font=("华文行楷", 20),
|
||
)
|
||
except:
|
||
btn = tkinter.Button(
|
||
top,
|
||
image=choice_photo,
|
||
command=lambda: choice("fromtab"),
|
||
font=("华文行楷", 20),
|
||
)
|
||
btn.place(relx=0.5, rely=0.5, anchor="center")
|
||
top.update()
|
||
total_width = btn.winfo_width()
|
||
total_height = btn.winfo_height() // 1.5
|
||
top.geometry(
|
||
"{}x{}+{}+{}".format(int(total_width) - 2, int(total_height), 0, 0)
|
||
)
|
||
top.update()
|
||
|
||
lz = tkinter.Button(zzz, text="←→", command=lambda: homework(pas=True, window=root))
|
||
lz.grid(column=0, row=0, sticky="nsew")
|
||
lf = tkinter.Button(zzz, text="复制", command=lambda: copy(zzz))
|
||
lf.grid(column=1, row=0, sticky="nsew")
|
||
adjust_font_size(lj, max_height=800 - he)
|
||
root.update_idletasks()
|
||
root.wm_attributes("-topmost", 0)
|
||
|
||
|
||
def check_resttime():
|
||
global zhou, d
|
||
try:
|
||
excel = xlrd.open_workbook("support/时刻表.xls") # 打开excel文件
|
||
sheet = excel.sheet_by_index(0) # 获取工作薄
|
||
rows: list = sheet.row_values(0) # 获取第一行的表头内容
|
||
index = rows.index("时刻表") # 获取age列所在的列数: 1,也可以换成"password"
|
||
listindes = sheet.col_values(index) # 获取age列的所有内容
|
||
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 count():
|
||
time.sleep(10)
|
||
|
||
|
||
def bsy(fro=None):
|
||
global top
|
||
if fro == None:
|
||
time.sleep(10)
|
||
while type(check_class()) == tuple:
|
||
try:
|
||
btn.config(text=check_class()[0][0] + "→" + check_class()[1][0])
|
||
time.sleep(check_resttime() + 3)
|
||
except tkinter.TclError:
|
||
time.sleep(check_resttime() + 3)
|
||
else:
|
||
if type(check_class()) == str:
|
||
btn.config(text=check_class())
|
||
else:
|
||
btn.config(text="", image=choice_photo)
|
||
top.update()
|
||
total_width = btn.winfo_width()
|
||
total_height = btn.winfo_height() // 1.5
|
||
top.geometry("{}x{}+{}+{}".format(total_width, int(total_height), 0, 0))
|
||
|
||
|
||
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 == "课程表.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 = [
|
||
"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
|
||
|
||
|
||
speed = 50
|
||
nodrag = False
|
||
flag_flag = True
|
||
t1 = Thread(
|
||
target=clean, name="clean"
|
||
) # 定义线程t1,线程任务为调用task1函数,task1函数的参数是6
|
||
t2 = Thread(
|
||
target=loading, name="main"
|
||
) # 定义线程t2,线程任务为调用task2函数,task2函数无参数
|
||
t3 = Thread(target=bsy, name="bsy")
|
||
t1.start() # 开始运行t1线程
|
||
t2.start() # 开始运行t2线程
|
||
time.sleep(5)
|
||
t3.start()
|