what/24-10-28.py

2072 lines
77 KiB
Python
Raw Normal View History

2024-10-29 15:35:50 +08:00
from threading import Thread
from tkinter import *
2024-11-03 22:05:22 +08:00
from arcade import load_sound, play_sound, stop_sound
2024-10-29 15:35:50 +08:00
from tkinter import font
import tkinter.filedialog
2024-11-03 22:05:22 +08:00
import random, tkinter, time, xlrd, datetime, logging, hashlib, os, shutil, pyperclip, requests, threading
2024-10-29 15:35:50 +08:00
from ttkbootstrap import Style
from tkinter import ttk
from docx import Document
from tkinter import messagebox
from PIL import Image, ImageTk
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def check_pwd(pwd):
global password
2024-11-03 22:05:22 +08:00
password = False
2024-10-29 15:35:50 +08:00
try:
2024-11-03 22:05:22 +08:00
with open("support/config.ini") as v:
2024-10-29 15:35:50 +08:00
for x in v.readlines():
2024-11-03 22:05:22 +08:00
if "pwd:" in x:
2024-10-29 15:35:50 +08:00
break
except:
2024-11-03 22:05:22 +08:00
on_button_click("没有找到密码文件", "")
pwd = "pwd:" + pwd
if pwd == x:
password = True
2024-10-29 15:35:50 +08:00
return True
else:
2024-11-03 22:05:22 +08:00
on_button_click("请检查密码", "")
2024-10-29 15:35:50 +08:00
return False
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def loading():
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
root = style.master
2024-11-03 22:05:22 +08:00
style.configure("TButton")
2024-10-29 15:35:50 +08:00
DraggableWindow(root)
screen_width = root.winfo_screenwidth()
2024-11-03 22:05:22 +08:00
screen_height = root.winfo_screenheight()
2024-10-29 15:35:50 +08:00
root.resizable(0, 0)
root.overrideredirect(1)
for x in range(75):
2024-11-03 22:05:22 +08:00
win_width = (4 * x) + 201
win_height = (4 * x) + 2
2024-10-29 15:35:50 +08:00
win_x = screen_width // 2 - win_width // 2
win_y = screen_height // 2 - win_height // 2 # 窗口垂直居中
2024-11-03 22:05:22 +08:00
root.geometry("{}x{}+{}+{}".format(win_width, win_height, win_x, win_y))
2024-10-29 15:35:50 +08:00
root.update()
root.update()
2024-11-03 22:05:22 +08:00
log("正在清理文件", "info")
while fin == False:
c = tkinter.Label(text=ll, font=("宋体", 10))
c.place(relx=0.5, rely=0.8, anchor="center")
2024-10-29 15:35:50 +08:00
time.sleep(0.08)
root.update_idletasks() # 刷新
root.update()
c.destroy()
else:
try:
c.destroy()
except:
pass
2024-11-03 22:05:22 +08:00
k = tkinter.Label(text="本次共清理了\n" + str(a) + "个文件", font=("宋体", 48))
log("本次共清理了" + str(a) + "个文件", "info")
k.place(relx=0.5, rely=0.5, anchor="center")
2024-10-29 15:35:50 +08:00
root.update()
root.after(1500)
k.destroy()
2024-11-03 22:05:22 +08:00
k = tkinter.Label(text="正在处理图片", font=("宋体", 24))
k.place(relx=0.5, rely=0.5, anchor="center")
2024-10-29 15:35:50 +08:00
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)
2024-11-03 22:05:22 +08:00
subjects = (
open("support/subjects", "r").read().splitlines()
) # 读取文件并分割成行
subjects.append("others")
2024-10-29 15:35:50 +08:00
image_dict = {}
for image_file in subjects:
try:
subphoto = Image.open("support/" + image_file + ".png")
except:
try:
2024-11-03 22:05:22 +08:00
file = requests.get(
"http://shenjack.top:5100/people/what/raw/branch/main/"
+ image_file
+ ".png"
)
open("support/" + image_file + ".png", "wb").write(file.content)
2024-10-29 15:35:50 +08:00
subphoto = Image.open("support/" + image_file + ".png")
except:
try:
subphoto = Image.open("support/others.png")
except:
try:
2024-11-03 22:05:22 +08:00
file = requests.get(
"http://shenjack.top:5100/people/what/raw/branch/main/others.png"
)
open("support/others.png", "wb").write(file.content)
2024-10-29 15:35:50 +08:00
subphoto = Image.open("support/others.png")
except:
subphoto = Image.open("support/up.png")
subphoto = subphoto.resize((40, 40))
subject_photo = ImageTk.PhotoImage(subphoto)
2024-11-03 22:05:22 +08:00
image_dict[os.path.basename(image_file)] = (
subject_photo # 将文件名作为键,图片对象作为值存储在字典中
)
schedule("fromclean")
2024-10-29 15:35:50 +08:00
root.mainloop()
2024-11-03 22:05:22 +08:00
def log(content, rate):
if rate == "info":
2024-10-29 15:35:50 +08:00
logging.info(content)
2024-11-03 22:05:22 +08:00
elif rate == "warning":
2024-10-29 15:35:50 +08:00
logging.warning(content)
2024-11-03 22:05:22 +08:00
elif rate == "error":
2024-10-29 15:35:50 +08:00
logging.error(content)
else:
2024-11-03 22:05:22 +08:00
logging.error("日志评级不正确,记录内容为:" + content)
with open("support/config.ini", "a+") as f:
a = f.readlines()
2024-10-29 15:35:50 +08:00
for x in range(len(a)):
2024-11-03 22:05:22 +08:00
if "日志处理后sha256" in a[x]:
2024-10-29 15:35:50 +08:00
del f.readlines()[x]
2024-11-03 22:05:22 +08:00
f.write("日志处理后sha256:" + file_sha256(r"support/journal.log"))
def on_button_click(content, pppp):
2024-10-29 15:35:50 +08:00
wait_window = tkinter.Toplevel(root)
2024-11-03 22:05:22 +08:00
wait_window.wm_attributes("-topmost", 1)
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
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就不开始移动窗口
2024-11-03 22:05:22 +08:00
if (
isinstance(event.widget, tkinter.Button)
or isinstance(event.widget, tkinter.Text)
or isinstance(event.widget, ttk.Button)
):
2024-10-29 15:35:50 +08:00
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就不移动窗口
2024-11-03 22:05:22 +08:00
if (
isinstance(event.widget, tkinter.Button)
or isinstance(event.widget, tkinter.Text)
or isinstance(event.widget, tkinter.Entry)
or nodrag == True
):
2024-10-29 15:35:50 +08:00
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}")
2024-11-03 22:05:22 +08:00
photo = None
info = ""
canceltopping = False
2024-10-29 15:35:50 +08:00
d = datetime.datetime.now()
2024-11-03 22:05:22 +08:00
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,
)
2024-10-29 15:35:50 +08:00
class PILFilter(logging.Filter):
def filter(self, record):
return record.name != "PIL" or record.levelno > logging.DEBUG
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
handler = logging.StreamHandler()
handler.addFilter(PILFilter())
# 设置日志级别和处理器
logging.basicConfig(level=logging.DEBUG, handlers=[handler])
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def file_hash(file_path: str, hash_method) -> str:
h = hash_method()
2024-11-03 22:05:22 +08:00
with open(file_path, "rb") as f:
2024-10-29 15:35:50 +08:00
while True:
b = f.read(8192)
if not b:
break
h.update(b)
f.close()
return h.hexdigest()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def file_sha256(file_path: str) -> str:
return file_hash(file_path, hashlib.sha256)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def check_class():
2024-11-03 22:05:22 +08:00
global zhou, d
2024-10-29 15:35:50 +08:00
try:
excel = xlrd.open_workbook("support/时刻表.xls") # 打开excel文件
sheet = excel.sheet_by_index(0) # 获取工作薄
rows: list = sheet.row_values(0) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index("时刻表") # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
for x in range(1, len(listindes)):
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
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) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index(
zhou[d.weekday()]
) # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
try:
2024-11-03 22:05:22 +08:00
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]
2024-10-29 15:35:50 +08:00
except:
return listindes[x]
return False
except:
return False
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def rest():
try:
excel = xlrd.open_workbook("support/时间表.xls") # 打开excel文件
sheet = excel.sheet_by_index(0) # 获取工作薄
rows: list = sheet.row_values(0) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index("时间表") # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
for x in range(1, len(listindes)):
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
now_time = datetime.datetime.now()
if start_time < now_time < end_time:
return True
return False
except:
return False
2024-11-03 22:05:22 +08:00
z = False
2024-10-29 15:35:50 +08:00
def countdown():
global speed
for btn in root.place_slaves():
btn.destroy()
def returnforpaused(whattime):
current_time = datetime.datetime.now().time()
2024-11-03 22:05:22 +08:00
current_datetime = datetime.datetime.combine(
datetime.date.today(), current_time
)
2024-10-29 15:35:50 +08:00
future_datetime = current_datetime + whattime
future_time = future_datetime.time().replace(microsecond=0)
return future_time
def paused(whattime):
2024-11-03 22:05:22 +08:00
global flag, star_photo
2024-10-29 15:35:50 +08:00
flag = False
2024-11-03 22:05:22 +08:00
pause = tkinter.Button(
image=star_photo,
command=lambda: updated(returnforpaused(whattime)),
font=("宋体", 30),
)
pause.grid(column=0, row=3, sticky="nsew")
2024-10-29 15:35:50 +08:00
def updated(future_time):
2024-11-03 22:05:22 +08:00
global starttime, flag, bigback_photo, stop_photo, paus_photo
2024-10-29 15:35:50 +08:00
flag = True
for child in root.grid_slaves():
child.grid_remove()
2024-11-03 22:05:22 +08:00
time1 = datetime.time(
int(str(future_time).split(":")[0]),
int(str(future_time).split(":")[1]),
int(str(future_time).split(":")[2]),
)
2024-10-29 15:35:50 +08:00
datetime1 = datetime.datetime.combine(datetime.date.today(), time1)
current_time = datetime.datetime.now().time()
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
while flag == True and datetime.datetime.now().time() <= (
2024-11-03 22:05:22 +08:00
datetime.time(
int(str(future_time).split(":")[0]),
int(str(future_time).split(":")[1]),
int(str(future_time).split(":")[2]),
)
):
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
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()
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
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()
2024-11-03 22:05:22 +08:00
current_datetime = datetime.datetime.combine(
datetime.date.today(), current_time
)
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
if unit == "hour":
if way == "+":
2024-10-29 15:35:50 +08:00
if hour >= 23:
pass
else:
hour = hour + 1
2024-11-03 22:05:22 +08:00
elif way == "-":
2024-10-29 15:35:50 +08:00
if hour <= 0:
pass
else:
hour = hour - 1
2024-11-03 22:05:22 +08:00
elif unit == "minute":
if way == "+":
2024-10-29 15:35:50 +08:00
if minute >= 59 and hour < 23:
hour = hour + 1
minute = minute % 59
elif minute >= 59 and hour >= 23:
pass
else:
minute = minute + 1
2024-11-03 22:05:22 +08:00
elif way == "-":
2024-10-29 15:35:50 +08:00
if minute <= 0:
pass
else:
minute = minute - 1
2024-11-03 22:05:22 +08:00
elif unit == "second":
if way == "+":
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
elif way == "-":
2024-10-29 15:35:50 +08:00
if second <= 0:
pass
else:
second = second - 1
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
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(
2024-11-03 22:05:22 +08:00
"{}x{}+{}+{}".format(
int(wid),
int(hei),
int(root.winfo_x() - step_x),
int(root.winfo_y() - step_y),
)
)
2024-10-29 15:35:50 +08:00
root.update()
root.geometry(
2024-11-03 22:05:22 +08:00
"{}x{}+{}+{}".format(
500,
300,
int(screen_width // 2 - 500 / 2),
int(screen_height // 2 - 300 / 2),
)
)
2024-10-29 15:35:50 +08:00
def welcome():
2024-11-03 22:05:22 +08:00
global \
starttime, \
hour, \
minute, \
second, \
flag, \
up_photo, \
down_photo, \
bigback_photo
2024-10-29 15:35:50 +08:00
for child in root.grid_slaves():
child.grid_remove()
hour = 0
minute = 0
second = 0
flag = False
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
root.mainloop()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
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)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def check_homework():
work = []
2024-11-03 22:05:22 +08:00
copylist = ""
subjects = open("support/subjects", "r").read().splitlines() # 读取文件并分割成行
2024-10-29 15:35:50 +08:00
for i, subject in enumerate(subjects):
2024-11-03 22:05:22 +08:00
if str(d.date()) + subject in os.listdir("support/homework/"):
with open("support/homework/" + str(d.date()) + subject, "r+") as f:
work.append(subject + "")
2024-10-29 15:35:50 +08:00
copylist = copylist + subject
l = 1
for x in f.readlines():
work.append(x)
if "——" in x:
2024-11-03 22:05:22 +08:00
copylist = copylist + x.split("——")[1]
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
copylist = copylist + str(l) + ")" + x
2024-10-29 15:35:50 +08:00
l = l + 1
return copylist
2024-11-03 22:05:22 +08:00
def homework(pas=None, window=None, line=9999):
global z, toplevel, back_photo, speed
z = True
if window == lo:
2024-10-29 15:35:50 +08:00
for child in root.grid_slaves():
2024-11-03 22:05:22 +08:00
cc = child.grid_info()
if cc["column"] == 1 and cc["row"] == line - 1:
2024-10-29 15:35:50 +08:00
child.grid_remove()
2024-11-03 22:05:22 +08:00
zxs = tkinter.Label(root, text=pas[0], font=("华文行楷", 40))
zxs.grid(column=1, row=line - 1)
2024-10-29 15:35:50 +08:00
reset_grid_configurations(window)
2024-11-03 22:05:22 +08:00
style.configure("TButton", font=("微软雅黑", 10))
if window != root:
2024-10-29 15:35:50 +08:00
window.configure(width=300)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def ex():
2024-11-03 22:05:22 +08:00
if window == lo:
schedule("fromhomework")
2024-10-29 15:35:50 +08:00
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)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
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) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index(
zhou[d.weekday()]
) # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
except:
2024-11-03 22:05:22 +08:00
listindes = "没有找到课程表文件"
log("课程表文件不存在", "error")
2024-10-29 15:35:50 +08:00
# 遍历该列所有的内容
2024-11-03 22:05:22 +08:00
zxs = tkinter.Label(right_area, text="", font=("华文行楷", 40))
2024-10-29 15:35:50 +08:00
zxs.grid(column=0, row=0)
window.update()
he = zxs.winfo_height()
wi = zxs.winfo_width()
zxs.destroy()
2024-11-03 22:05:22 +08:00
style.configure("TButton", font=("华文行楷", 40))
2024-10-29 15:35:50 +08:00
for i in range(1, len(listindes)):
2024-11-03 22:05:22 +08:00
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]:
2024-10-29 15:35:50 +08:00
window.grid_rowconfigure(i - 1, weight=1)
zxs = tkinter.Frame(right_area, height=he, width=wi)
2024-11-03 22:05:22 +08:00
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 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
zxs = tkinter.Label(
right_area, text=listindes[i], font=("华文行楷", 20)
)
2024-10-29 15:35:50 +08:00
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()
2024-11-03 22:05:22 +08:00
ppp = tkinter.Text(too, font=("黑体", 24))
2024-10-29 15:35:50 +08:00
window.update()
2024-11-03 22:05:22 +08:00
co = tkinter.Text(too, width=ppp.cget("width"), font=("黑体", 36))
2024-10-29 15:35:50 +08:00
co.focus_set()
co.insert("insert", con)
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
window.update()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def look():
global cross_photo
for child in window.grid_slaves():
child.grid_remove()
for t in window.place_slaves():
t.destroy()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def secure():
2024-11-03 22:05:22 +08:00
pasd("")
2024-10-29 15:35:50 +08:00
secure()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def pasd(copylist):
2024-11-03 22:05:22 +08:00
global too, right_area, nodrag
nodrag = True
if copylist == "" or copylist == "refresh":
if copylist == "":
2024-10-29 15:35:50 +08:00
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(
2024-11-03 22:05:22 +08:00
"{}x{}+{}+{}".format(int(wid), int(hei), int(xxx), int(yyy))
)
2024-10-29 15:35:50 +08:00
window.update()
2024-11-03 22:05:22 +08:00
window.geometry("{}x{}+{}+{}".format(screen_width, screen_height, 0, 0))
2024-10-29 15:35:50 +08:00
window.grid_rowconfigure(0, weight=1)
too = tkinter.Frame(window)
2024-11-03 22:05:22 +08:00
too.grid(column=0, row=0, sticky="nsew")
2024-10-29 15:35:50 +08:00
right_area = tkinter.Frame(window, height=screen_height)
2024-11-03 22:05:22 +08:00
right_area.grid(row=0, column=1, sticky="nsew")
2024-10-29 15:35:50 +08:00
window.grid_rowconfigure(0, weight=1) # too 所在的列
window.grid_columnconfigure(0, weight=1) # too 所在的列
2024-11-03 22:05:22 +08:00
window.grid_columnconfigure(
1, minsize=55, weight=0
) # right_area 所在的列,固定宽度
2024-10-29 15:35:50 +08:00
right_area.configure(width=55)
schedule_for_view()
2024-11-03 22:05:22 +08:00
elif copylist == "refresh":
2024-10-29 15:35:50 +08:00
for child in too.grid_slaves():
child.grid_remove()
for t in too.place_slaves():
t.destroy()
2024-11-03 22:05:22 +08:00
copylist = check_homework()
pyperclip.copy(str(d.date()) + "\n" + copylist)
2024-10-29 15:35:50 +08:00
doc = Document()
# 这里相当于输入了一个空格,后面等待着文字输入
paragraph3 = doc.add_paragraph()
2024-11-03 22:05:22 +08:00
paragraph3.add_run("请勿在此处更改,不会被保存。\n" + copylist)
2024-10-29 15:35:50 +08:00
try:
2024-11-03 22:05:22 +08:00
doc.save("support/" + str(d.date()) + "作业.docx")
2024-10-29 15:35:50 +08:00
except:
2024-11-03 22:05:22 +08:00
on_button_click("请将word窗口关闭", "")
2024-10-29 15:35:50 +08:00
window.update()
else:
for child in too.grid_slaves():
child.grid_remove()
for t in too.place_slaves():
t.destroy()
2024-11-03 22:05:22 +08:00
tkinter.Label(
too,
text=" ",
font=("黑体", 24),
wraplength=root.winfo_width(),
).grid(column=0, row=0, sticky="nsew")
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
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())
2024-10-29 15:35:50 +08:00
zzz = tkinter.Frame(too)
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
li = tkinter.Button(zzz, image=pen_photo, command=lambda: edit(copylist))
2024-11-03 22:05:22 +08:00
li.grid(column=2, row=0, sticky="nsew")
zzz.grid(column=0, row=2, sticky="nsew")
2024-10-29 15:35:50 +08:00
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()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def add_subject(a):
2024-11-03 22:05:22 +08:00
with open("support/subjects", "r+") as h:
if a + "\n" in h.readlines():
tkinter.messagebox.showwarning("已存在", a + "已存在")
2024-10-29 15:35:50 +08:00
h.close()
2024-11-03 22:05:22 +08:00
elif a == "":
2024-10-29 15:35:50 +08:00
return False
else:
2024-11-03 22:05:22 +08:00
with open("support/subjects", "a+") as g:
g.write(str(a) + "\n")
2024-10-29 15:35:50 +08:00
g.close()
choice_book(a)
2024-11-03 22:05:22 +08:00
def edit_homework(sub, subject, book, line):
2024-10-29 15:35:50 +08:00
for child in window.grid_slaves():
2024-11-03 22:05:22 +08:00
if child.grid_info()["row"] == line:
2024-10-29 15:35:50 +08:00
child.grid_remove()
2024-11-03 22:05:22 +08:00
ppp = tkinter.Text(
window,
height=2,
)
2024-10-29 15:35:50 +08:00
ppp.focus_set()
ppp.insert("insert", subject)
2024-11-03 22:05:22 +08:00
ppp.bind("<Key>", handle_return)
2024-10-29 15:35:50 +08:00
ppp.grid(row=line, column=0, ipadx=30, padx=10)
2024-11-03 22:05:22 +08:00
button = tkinter.Button(
window,
image=tick_photo,
command=lambda: rewrite_homework(
sub, subject, book, ppp.get(1.0, END).strip()
),
) # 使用 lambda 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
button.grid(row=line, column=2, ipadx=1, pady=5) # 假设你只使用一列
2024-11-03 22:05:22 +08:00
def rewrite_homework(sub, subject, book, content):
with open("support/homework/" + str(d.date()) + sub, "r") as file:
2024-10-29 15:35:50 +08:00
lines = file.readlines()
# 遍历每一行检查是否有内容为”123“的行
for i, line in enumerate(lines):
if line.strip() == subject:
# 如果有,删除这一行
del lines[i]
break
2024-11-03 22:05:22 +08:00
lines.append(content + "\n")
with open("support/homework/" + str(d.date()) + sub, "w") as file:
2024-10-29 15:35:50 +08:00
file.writelines(lines)
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
pass
try:
window.update()
2024-11-03 22:05:22 +08:00
add_work(sub, book)
2024-10-29 15:35:50 +08:00
except:
pass
2024-11-03 22:05:22 +08:00
if window != lo:
pasd("refresh")
def delete_homework(sub, subject, book):
with open("support/homework/" + str(d.date()) + sub, "r") as file:
2024-10-29 15:35:50 +08:00
lines = file.readlines()
# 遍历每一行检查是否有内容为”123“的行
for i, line in enumerate(lines):
if line.strip() == subject:
# 如果有,删除这一行
del lines[i]
break
# 将修改后的内容写回文件
2024-11-03 22:05:22 +08:00
with open("support/homework/" + str(d.date()) + sub, "w") as file:
2024-10-29 15:35:50 +08:00
file.writelines(lines)
2024-11-03 22:05:22 +08:00
if window != lo:
pasd("refresh")
add_work(sub, book)
2024-10-29 15:35:50 +08:00
def handle_return(event):
2024-11-03 22:05:22 +08:00
if event.keysym == "Return":
homework_input_box.insert(END, "\n——")
return "break"
def add_work(sub, book):
2024-10-29 15:35:50 +08:00
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:
2024-11-03 22:05:22 +08:00
subjects = (
open("support/homework/" + str(d.date()) + sub, "r+")
.read()
.splitlines()
) # 读取文件并分割成行
2024-10-29 15:35:50 +08:00
except:
2024-11-03 22:05:22 +08:00
with open("support/homework/" + str(d.date()) + sub, "w+") as f:
2024-10-29 15:35:50 +08:00
pass
2024-11-03 22:05:22 +08:00
subjects = (
open("support/homework/" + str(d.date()) + sub, "r+")
.read()
.splitlines()
)
i = 2
2024-10-29 15:35:50 +08:00
for i, subject in enumerate(subjects):
2024-11-03 22:05:22 +08:00
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 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
button.grid(row=i + 1, column=1, ipadx=1, pady=5) # 假设你只使用一列
2024-11-03 22:05:22 +08:00
button = tkinter.Button(
window,
image=cross_photo,
command=lambda subject=subject: delete_homework(sub, subject, book),
bg="#4472c4",
activebackground="#4472c4",
fg="white",
) # 使用 lambda 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
button.grid(row=i + 1, column=2, ipadx=1, pady=5) # 假设你只使用一列
2024-11-03 22:05:22 +08:00
def confirm(sub, book, content):
if content == "":
2024-10-29 15:35:50 +08:00
choice_book(sub)
else:
for child in window.grid_slaves():
child.grid_remove()
for t in window.place_slaves():
t.destroy()
2024-11-03 22:05:22 +08:00
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)
2024-10-29 15:35:50 +08:00
global homework_input_box
2024-11-03 22:05:22 +08:00
homework_input_box = tkinter.Text(
window,
height=20,
)
2024-10-29 15:35:50 +08:00
homework_input_box.focus_set()
2024-11-03 22:05:22 +08:00
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 == "":
2024-10-29 15:35:50 +08:00
return False
2024-11-03 22:05:22 +08:00
elif book + "\n" in f.readlines():
tkinter.messagebox.showwarning("已存在", book + "已存在")
elif len(open("support/" + sub, "r+").read().splitlines()) >= 12:
tkinter.messagebox.showwarning(
"已达上限", "最多添加12个常用书删除功能还在测试敬请期待。"
)
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
with open("support/" + sub, "a+") as g:
g.write(book + "\n")
2024-10-29 15:35:50 +08:00
g.close()
f.close()
2024-11-03 22:05:22 +08:00
add_work(sub, book)
2024-10-29 15:35:50 +08:00
def choice_book(sub):
for child in window.grid_slaves():
child.grid_remove()
for t in window.place_slaves():
t.destroy()
try:
2024-11-03 22:05:22 +08:00
subjects = (
open("support/" + sub, "r+").read().splitlines()
) # 读取文件并分割成行
2024-10-29 15:35:50 +08:00
except:
2024-11-03 22:05:22 +08:00
with open("support/" + sub, "w+") as f:
f.write("")
2024-10-29 15:35:50 +08:00
f.close()
2024-11-03 22:05:22 +08:00
subjects = open("support/" + sub, "r+").read().splitlines()
i = 2
2024-10-29 15:35:50 +08:00
2024-11-03 22:05:22 +08:00
tkinter.Label(
window,
text="\n\n"
+ sub
+ "\n"
+ "选择或输入书名或卷名\n可将此栏目中的内容添加为常用书",
).grid(row=0, column=0, ipadx=15, pady=10, columnspan=2, sticky="nsew")
2024-10-29 15:35:50 +08:00
for i, subject in enumerate(subjects):
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
ppp = tkinter.Entry(window, width=10)
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
window.update()
pass
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def window_close_handle():
2024-11-03 22:05:22 +08:00
global z, toplevel
z = False
2024-10-29 15:35:50 +08:00
window.destroy()
try:
toplevel.overrideredirect(1)
except:
pass
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
for x in window.place_slaves():
x.place_forget()
for child in window.grid_slaves():
child.grid_remove()
2024-11-03 22:05:22 +08:00
if window == root:
window.protocol("WM_DELETE_WINDOW", window_close_handle)
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def the():
for child in window.grid_slaves():
child.grid_remove()
for t in window.place_slaves():
t.destroy()
2024-11-03 22:05:22 +08:00
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
2024-10-29 15:35:50 +08:00
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 属性,并获取其名称(而不是尝试调用它)
2024-11-03 22:05:22 +08:00
if hasattr(thread, "target"):
target_name = (
thread.target.__name__
if callable(thread.target)
else str(thread.target)
)
2024-10-29 15:35:50 +08:00
target_label = tkinter.Label(window, text=target_name)
else:
2024-11-03 22:05:22 +08:00
target_label = tkinter.Label(
window, text="None"
) # 对于没有 target 的线程,显示 "None"
2024-10-29 15:35:50 +08:00
target_label.grid(column=2, row=a)
if thread.is_alive():
2024-11-03 22:05:22 +08:00
tkinter.Button(
window,
text="停止",
command=lambda: tkinter.messagebox.showwarning(
"", "暂不支持此功能"
),
).grid(column=3, row=a)
2024-10-29 15:35:50 +08:00
else:
try:
2024-11-03 22:05:22 +08:00
tkinter.Button(
window,
text="启动",
command=lambda: tkinter.messagebox.showwarning(
"", "暂不支持此功能"
),
).grid(column=3, row=a)
2024-10-29 15:35:50 +08:00
except Exception as e:
2024-11-03 22:05:22 +08:00
tkinter.messagebox.showwarning("", str(e))
a = a + 1
tkinter.Label(window, text="v24.10.28 ©曾祥盛").grid(
column=0, row=a + 1, columnspan=4
)
2024-10-29 15:35:50 +08:00
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()
2024-11-03 22:05:22 +08:00
subjects = (
open("support/subjects", "r").read().splitlines()
) # 读取文件并分割成行
tkinter.Label(window, text="请选择科目").grid(
row=0, column=0, pady=10, columnspan=2, sticky="nsew"
)
2024-10-29 15:35:50 +08:00
for i, subject in enumerate(subjects):
try:
2024-11-03 22:05:22 +08:00
button = ttk.Button(
window,
image=image_dict[subject],
compound="left",
text=subject,
command=lambda subject=subject: choice_book(subject),
style="light.TButton",
) # 使用 lambda 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
except:
2024-11-03 22:05:22 +08:00
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
) # 假设你只使用一列
2024-10-29 15:35:50 +08:00
ppp = tkinter.Entry(window, width=10)
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
if sub != None:
if sub in subjects:
choice_book(sub)
window.update()
2024-11-03 22:05:22 +08:00
if pas == True:
pasd("")
2024-10-29 15:35:50 +08:00
elif pas != None:
choice_subject(pas)
else:
choice_subject()
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def choice(fromwhere):
2024-11-03 22:05:22 +08:00
global \
info, \
canceltopping, \
zhou, \
h, \
d, \
photo, \
label_img, \
chosed, \
shouldnot, \
password, \
speed
root.wm_attributes("-topmost", 1)
2024-10-29 15:35:50 +08:00
top.destroy()
for btn in root.place_slaves():
btn.destroy()
for x in root.grid_slaves():
x.grid_remove()
root.overrideredirect(1)
2024-11-03 22:05:22 +08:00
if fromwhere == "fromschedule":
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
step_y = ((screen_height // 2 - win_height // 2) - root.winfo_y()) / speed
2024-10-29 15:35:50 +08:00
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() - step_hei
root.geometry(
2024-11-03 22:05:22 +08:00
"{}x{}+{}+{}".format(
int(wid),
int(hei),
int(root.winfo_x() + step_x),
int(root.winfo_y() + step_y),
)
)
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
root.geometry("{}x{}+{}+{}".format(win_width, win_height, win_x, win_y))
elif fromwhere == "fromtab":
2024-10-29 15:35:50 +08:00
step_wid = (400 - root.winfo_width()) / speed
step_hei = (root.winfo_height() - 300) / speed
2024-11-03 22:05:22 +08:00
step_x = root.winfo_x() / speed
step_y = root.winfo_y() / speed
2024-10-29 15:35:50 +08:00
for x in range(speed):
wid = root.winfo_width() + step_wid
hei = root.winfo_height() - step_hei
root.geometry(
2024-11-03 22:05:22 +08:00
"{}x{}+{}+{}".format(
int(wid),
int(hei),
int(root.winfo_x() - step_x),
int(root.winfo_y() - step_y),
)
)
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
root.geometry("{}x{}+{}+{}".format(400, 300, 0, 0))
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
root.title("随机选人")
2024-10-29 15:35:50 +08:00
global list
list = []
2024-11-03 22:05:22 +08:00
status = "开始"
back = tkinter.Button(
text="返回", command=lambda: schedule("fromchoice"), font=("微软雅黑", 10)
)
back.place(relx=1, rely=0, anchor="ne")
2024-10-29 15:35:50 +08:00
verify = tkinter.Button(image=countdown_photo, command=lambda: countdown())
2024-11-03 22:05:22 +08:00
verify.place(relx=0, rely=0, anchor="nw")
2024-10-29 15:35:50 +08:00
nolis = tkinter.StringVar()
nolis.set(False)
2024-11-03 22:05:22 +08:00
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')
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
inn = tkinter.Label(text="正在处理……", font=("微软雅黑", 10))
inn.place(relx=0.5, rely=0.5, anchor="center")
with open("support/record.txt", "r") as k:
2024-10-29 15:35:50 +08:00
for re in k.readlines():
2024-11-03 22:05:22 +08:00
if not re.strip("\n") in chosed:
chosed.append(re.strip("\n"))
2024-10-29 15:35:50 +08:00
k.close()
try:
2024-11-03 22:05:22 +08:00
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 = []
2024-10-29 15:35:50 +08:00
for x in c.readlines():
jour.append(x)
c.close()
for x in range(len(jour) - 1, -1, -1):
2024-11-03 22:05:22 +08:00
if "当前有" in jour[x]:
file_name = jour[x].split("当前有")[1]
episode_name = file_name.split("")[0]
2024-10-29 15:35:50 +08:00
break
2024-11-03 22:05:22 +08:00
for y in range(len(jour) - 1, -1, -1):
if "人名单sha256:" in jour[y]:
fi = jour[y].split("sha256:")
2024-10-29 15:35:50 +08:00
break
2024-11-03 22:05:22 +08:00
zz = file_sha256(r"support/1.txt") + "\n"
2024-10-29 15:35:50 +08:00
try:
try:
if zz != fi[1]:
if rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。",
"",
)
2024-10-29 15:35:50 +08:00
elif not rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。",
"pppp",
)
2024-10-29 15:35:50 +08:00
else:
password = True
except:
2024-11-03 22:05:22 +08:00
log("人名单sha256:" + file_sha256(r"support/1.txt"), "info")
password = True
2024-10-29 15:35:50 +08:00
except:
pass
2024-11-03 22:05:22 +08:00
if (rest()) or (not rest() and password == True):
log("人名单sha256:" + file_sha256(r"support/1.txt"), "info")
log("当前有" + str(len(list)) + "", "info")
password = False
2024-10-29 15:35:50 +08:00
except Exception as e:
2024-11-03 22:05:22 +08:00
on_button_click("没有找到人名单文件或因\n" + str(e), "")
log("人名单文件不存在", "info")
schedule("fromchoice")
2024-10-29 15:35:50 +08:00
root.quit()
try:
2024-11-03 22:05:22 +08:00
for z in range(len(jour) - 1, -1, -1):
if "操作后sha256:" in jour[z]:
ooo = (jour[z].split("sha256:"))[1]
2024-10-29 15:35:50 +08:00
break
2024-11-03 22:05:22 +08:00
sha = file_sha256(r"support/record.txt") + "\n"
2024-10-29 15:35:50 +08:00
try:
if ooo != sha:
if rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。",
"",
)
2024-10-29 15:35:50 +08:00
elif not rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。",
"pppp",
)
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
password = True
2024-10-29 15:35:50 +08:00
if (rest()) or (not rest() and password == True):
2024-11-03 22:05:22 +08:00
log("操作后sha256:" + file_sha256(r"support/record.txt"), "info")
2024-10-29 15:35:50 +08:00
password = False
except:
pass
except:
pass
try:
2024-11-03 22:05:22 +08:00
with open("support/config.ini", "r+") as file:
2024-10-29 15:35:50 +08:00
for z in file.readlines():
2024-11-03 22:05:22 +08:00
if "日志处理后sha256:" in jour[z]:
jourlog = (jour[z].split("sha256:"))[1]
2024-10-29 15:35:50 +08:00
break
2024-11-03 22:05:22 +08:00
sha = file_sha256(r"support/journal.log") + "\n"
2024-10-29 15:35:50 +08:00
try:
if jourlog != sha:
if rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。",
"",
)
2024-10-29 15:35:50 +08:00
elif not rest():
2024-11-03 22:05:22 +08:00
on_button_click(
"日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。",
"pppp",
)
2024-10-29 15:35:50 +08:00
else:
password = True
if (rest()) or (not rest() and password == True):
2024-11-03 22:05:22 +08:00
log("", "info")
2024-10-29 15:35:50 +08:00
password = False
except:
pass
except:
pass
try:
if int(episode_name) != len(list):
2024-11-03 22:05:22 +08:00
on_button_click(
"人名单中的人数\n与上次运行时不一致,\n请检查人名单是否被篡改。\n按确定以继续。",
"",
)
2024-10-29 15:35:50 +08:00
for i in set(list):
if list.count(i) > 1:
2024-11-03 22:05:22 +08:00
if on_button_click(
"在人名单文件中,"
+ i
+ "出现了"
+ str(list.count(i))
+ "次,\n请检查人名单是否被篡改。\n重复的元素将会引发程序错误,\n在删除重复的元素之前请勿运行此模块。\n按确定以退出。",
"",
):
schedule("fromchoice")
2024-10-29 15:35:50 +08:00
elif i in shouldnot:
2024-11-03 22:05:22 +08:00
on_button_click(
'人名单中出现不该出现的\n"'
+ i
+ '"\n请检查人名单是否被篡改。\n按确定以继续。',
"",
)
2024-10-29 15:35:50 +08:00
except:
pass
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def stop(r):
global flag, status, list, info, a, chosed, inf
flag = True
2024-11-03 22:05:22 +08:00
status = "开始"
2024-10-29 15:35:50 +08:00
if not rest():
inf = tkinter.Label(
2024-11-03 22:05:22 +08:00
text="当前有"
+ info
+ "人。\n现在处于下课时间,抽到的人将不会添加到已抽中列表。",
font=("微软雅黑", 10),
)
elif str(nolis.get()) == "1":
2024-10-29 15:35:50 +08:00
inf = tkinter.Label(
2024-11-03 22:05:22 +08:00
text="当前有"
+ info
+ "人。已忽略已抽中列表。\n抽到的人将不会添加到已抽中列表。",
font=("微软雅黑", 10),
)
2024-10-29 15:35:50 +08:00
else:
chosed.append(r)
2024-11-03 22:05:22 +08:00
log("本次抽中" + r, "info")
with open("support/record.txt", "a+") as p:
p.write(r + "\n")
2024-10-29 15:35:50 +08:00
p.close()
2024-11-03 22:05:22 +08:00
log("操作后sha256:" + file_sha256(r"support/record.txt"), "info")
2024-10-29 15:35:50 +08:00
inf = tkinter.Label(
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
def main():
global flag, root, list, status, info, a, chosed, inf
try:
inf.destroy()
except:
pass
flag = False
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
while not flag:
r = random.randint(0, len(list) - 1)
2024-11-03 22:05:22 +08:00
if len(chosed) == len(list) - 5:
2024-10-29 15:35:50 +08:00
chosed.clear()
2024-11-03 22:05:22 +08:00
with open("support/record.txt", "a+") as g:
2024-10-29 15:35:50 +08:00
g.truncate(0)
g.close()
2024-11-03 22:05:22 +08:00
log("操作后sha256:" + file_sha256(r"support/record.txt"), "info")
if (list[r] not in chosed) and (int(nolis.get()) == 0):
2024-10-29 15:35:50 +08:00
try:
a.destroy()
except:
pass
2024-11-03 22:05:22 +08:00
a = tkinter.Label(text=list[r], width=30, font=("华文行楷", 72))
a.place(relx=0.5, rely=0.4, anchor="center")
2024-10-29 15:35:50 +08:00
root.update()
time.sleep(0.01)
2024-11-03 22:05:22 +08:00
elif int(nolis.get()) == 1:
2024-10-29 15:35:50 +08:00
try:
a.destroy()
except:
pass
2024-11-03 22:05:22 +08:00
a = tkinter.Label(text=list[r], width=30, font=("华文行楷", 72))
a.place(relx=0.5, rely=0.4, anchor="center")
2024-10-29 15:35:50 +08:00
root.update()
time.sleep(0.01)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
flag = False
2024-11-03 22:05:22 +08:00
status = "开始"
2024-10-29 15:35:50 +08:00
inn.destroy()
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
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()
# 判断是否满足条件
2024-11-03 22:05:22 +08:00
if (max_width is None or text_width <= label_width) and (
max_height is None or text_height <= label_height
):
2024-10-29 15:35:50 +08:00
break
# 字体大小递减(避免无限循环)
font_size -= 1
# 检查是否已达到最小字体大小
if font_size < min_size:
2024-11-03 22:05:22 +08:00
label.config(text="字数过多")
font_size = 48
2024-10-29 15:35:50 +08:00
def copy(lg):
2024-11-03 22:05:22 +08:00
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())
2024-10-29 15:35:50 +08:00
def schedule(fr):
2024-11-03 22:05:22 +08:00
global \
thu, \
other, \
zhou, \
d, \
canceltopping, \
photo, \
lose, \
hh, \
h, \
no, \
z, \
speed, \
nodrag, \
top, \
btn, \
lo
root.wm_attributes("-topmost", 0)
2024-10-29 15:35:50 +08:00
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)
2024-11-03 22:05:22 +08:00
if lose == []:
2024-10-29 15:35:50 +08:00
pass
else:
2024-11-03 22:05:22 +08:00
a = "缺少关键组件:\n"
2024-10-29 15:35:50 +08:00
for x in lose:
2024-11-03 22:05:22 +08:00
a = a + x + "\n"
on_button_click(a, "")
lose = []
2024-10-29 15:35:50 +08:00
if 1:
step_wid = (359 - root.winfo_width()) / speed
step_hei = (800 - root.winfo_height()) / speed
2024-11-03 22:05:22 +08:00
step_x = (root.winfo_x() - (screen_width - 359)) / speed
2024-10-29 15:35:50 +08:00
step_y = (root.winfo_y() - 0) / speed
2024-11-03 22:05:22 +08:00
wid = root.winfo_width()
hei = root.winfo_height()
xxx = root.winfo_x()
yyy = root.winfo_y()
2024-10-29 15:35:50 +08:00
# 移动窗口到指定位置,并有动画效果
for x in range(speed):
wid = wid + step_wid
hei = hei + step_hei
2024-11-03 22:05:22 +08:00
xxx = xxx - step_x
yyy = yyy - step_y
root.geometry("{}x{}+{}+{}".format(int(wid), int(hei), int(xxx), int(yyy)))
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
root.geometry("{}x{}+{}+{}".format(359, 800, screen_width - 359, 0))
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
root.title("课程表")
2024-10-29 15:35:50 +08:00
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) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index(
zhou[d.weekday()]
) # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
except:
2024-11-03 22:05:22 +08:00
on_button_click("请确认课程表文件\n存在且格式正确", "")
log("课程表文件不存在", "error")
2024-10-29 15:35:50 +08:00
root.quit()
# 遍历该列所有的内容
2024-11-03 22:05:22 +08:00
style.configure("TButton", font=("华文行楷", 40))
zxs = tkinter.Label(root, text="", font=("华文行楷", 40))
2024-10-29 15:35:50 +08:00
zxs.grid(column=1, row=0)
root.update()
2024-11-03 22:05:22 +08:00
he = zxs.winfo_height()
2024-10-29 15:35:50 +08:00
wi = zxs.winfo_width()
zxs.destroy()
2024-11-03 22:05:22 +08:00
lo = tkinter.Frame(root, width=300)
2024-10-29 15:35:50 +08:00
lo.grid_propagate(False)
# 使用配置好的样式创建按钮
for i in range(1, len(listindes)):
2024-11-03 22:05:22 +08:00
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 函数打印按钮的文本
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
zxs = tkinter.Label(root, text=listindes[i], font=("华文行楷", 20))
zxs.grid(column=1, row=i - 1)
2024-10-29 15:35:50 +08:00
root.update()
listindes.clear()
2024-11-03 22:05:22 +08:00
y = tkinter.Button(text=zhou[d.weekday()], command=lambda: choice("fromtab"))
y.grid(row=i, column=1, sticky="nsew")
global h, labeled
2024-10-29 15:35:50 +08:00
root.grid_columnconfigure(0, weight=1)
2024-11-03 22:05:22 +08:00
lw = tkinter.Label(lo, text=str(d.date()), font=("微软雅黑", 20))
lw.grid(column=0, row=0, sticky="nsew")
2024-10-29 15:35:50 +08:00
root.update()
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
zzz = tkinter.Frame(root)
2024-11-03 22:05:22 +08:00
zzz.grid(column=0, row=i, sticky="nsew")
2024-10-29 15:35:50 +08:00
zzz.grid_columnconfigure(0, weight=1)
zzz.grid_columnconfigure(1, weight=1)
2024-11-03 22:05:22 +08:00
if fr != "fromhomework":
2024-10-29 15:35:50 +08:00
top = tkinter.Toplevel()
top.resizable(False, False)
top.overrideredirect(True)
2024-11-03 22:05:22 +08:00
top.wm_attributes("-topmost", 1)
2024-10-29 15:35:50 +08:00
try:
2024-11-03 22:05:22 +08:00
if type(check_class()) == tuple:
btn = tkinter.Button(
top,
text=check_class()[0][0] + "" + check_class()[1][0],
command=lambda: choice("fromtab"),
font=("华文行楷", 20),
)
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
btn = tkinter.Button(
top,
text=check_class(),
command=lambda: choice("fromtab"),
font=("华文行楷", 20),
)
2024-10-29 15:35:50 +08:00
except TypeError:
try:
2024-11-03 22:05:22 +08:00
btn = tkinter.Button(
top,
text=check_class()[0][0],
command=lambda: choice("fromtab"),
font=("华文行楷", 20),
)
2024-10-29 15:35:50 +08:00
except:
2024-11-03 22:05:22 +08:00
btn = tkinter.Button(
top,
image=choice_photo,
command=lambda: choice("fromtab"),
font=("华文行楷", 20),
)
btn.place(relx=0.5, rely=0.5, anchor="center")
2024-10-29 15:35:50 +08:00
top.update()
total_width = btn.winfo_width()
total_height = btn.winfo_height() // 1.5
2024-11-03 22:05:22 +08:00
top.geometry(
"{}x{}+{}+{}".format(int(total_width) - 2, int(total_height), 0, 0)
)
2024-10-29 15:35:50 +08:00
top.update()
2024-11-03 22:05:22 +08:00
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)
2024-10-29 15:35:50 +08:00
root.update_idletasks()
2024-11-03 22:05:22 +08:00
root.wm_attributes("-topmost", 0)
2024-10-29 15:35:50 +08:00
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) # 获取第一行的表头内容
2024-11-03 22:05:22 +08:00
index = rows.index("时刻表") # 获取age列所在的列数: 1也可以换成"password"
2024-10-29 15:35:50 +08:00
listindes = sheet.col_values(index) # 获取age列的所有内容
for x in range(1, len(listindes)):
2024-11-03 22:05:22 +08:00
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"
)
2024-10-29 15:35:50 +08:00
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
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def count():
time.sleep(10)
2024-11-03 22:05:22 +08:00
2024-10-29 15:35:50 +08:00
def bsy(fro=None):
global top
2024-11-03 22:05:22 +08:00
if fro == None:
2024-10-29 15:35:50 +08:00
time.sleep(10)
2024-11-03 22:05:22 +08:00
while type(check_class()) == tuple:
2024-10-29 15:35:50 +08:00
try:
2024-11-03 22:05:22 +08:00
btn.config(text=check_class()[0][0] + "" + check_class()[1][0])
2024-10-29 15:35:50 +08:00
time.sleep(check_resttime() + 3)
except tkinter.TclError:
time.sleep(check_resttime() + 3)
else:
2024-11-03 22:05:22 +08:00
if type(check_class()) == str:
2024-10-29 15:35:50 +08:00
btn.config(text=check_class())
else:
2024-11-03 22:05:22 +08:00
btn.config(text="", image=choice_photo)
2024-10-29 15:35:50 +08:00
top.update()
total_width = btn.winfo_width()
2024-11-03 22:05:22 +08:00
total_height = btn.winfo_height() // 1.5
top.geometry("{}x{}+{}+{}".format(total_width, int(total_height), 0, 0))
2024-10-29 15:35:50 +08:00
def clean():
2024-11-03 22:05:22 +08:00
global fin, a, ll, lose
ll = "正在清理文件"
fin = False
2024-10-29 15:35:50 +08:00
a = 0
current_dir = os.getcwd()
2024-11-03 22:05:22 +08:00
uncommon_dir = os.path.join(current_dir, "不常用的文件")
2024-10-29 15:35:50 +08:00
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)
2024-11-03 22:05:22 +08:00
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
2024-10-29 15:35:50 +08:00
elif os.path.getmtime(filepath) < one_week_ago.timestamp():
2024-11-03 22:05:22 +08:00
ll = "移动" + filename
2024-10-29 15:35:50 +08:00
try:
shutil.move(filepath, os.path.join(uncommon_dir, filename))
2024-11-03 22:05:22 +08:00
log("移动了" + filename, "info")
2024-10-29 15:35:50 +08:00
except Exception as e:
2024-11-03 22:05:22 +08:00
log("移动" + str(filename) + "失败,因为" + str(e), "warning")
2024-10-29 15:35:50 +08:00
a = a + 1
else:
2024-11-03 22:05:22 +08:00
ll = filename + "未到过期时间"
ll = "正在检查程序组件"
x = os.listdir("support")
list = [
"temp.txt",
"课程表.xls",
"时间表.xls",
"时刻表.xls",
"1.txt",
"journal.log",
"record.txt",
"config.ini",
]
lose = []
2024-10-29 15:35:50 +08:00
for y in list:
2024-11-03 22:05:22 +08:00
ll = "检查" + y
2024-10-29 15:35:50 +08:00
if y in x:
2024-11-03 22:05:22 +08:00
ll = "存在" + y
2024-10-29 15:35:50 +08:00
else:
2024-11-03 22:05:22 +08:00
ll = "缺少" + y
2024-10-29 15:35:50 +08:00
lose.append(y)
2024-11-03 22:05:22 +08:00
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")
2024-10-29 15:35:50 +08:00
t1.start() # 开始运行t1线程
t2.start() # 开始运行t2线程
time.sleep(5)
2024-11-03 22:05:22 +08:00
t3.start()