import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
import sys, os
import datetime as dt
import platform
try:
import openpyxl as px
except:
os.system("pip install openpyxl")
import openpyxl as px
#生成题库模板格式
wb1 = px.Workbook()
ws1 = wb1.active
ws1.cell(1, 1).value = "序号"
ws1.cell(1, 2).value = "题型"
ws1.cell(1, 3).value = "题干"
ws1.cell(1, 4).value = "参考答案"
ws1.cell(1, 5).value = "A"
ws1.cell(1, 6).value = "B"
ws1.cell(1, 7).value = "C"
ws1.cell(1, 8).value = "D"
ws1.cell(1, 10).value = "出错次数"
ws1.cell(1, 11).value = "正确次数"
ws1.cell(1, 12).value = "最后正误"
ws1.cell(1, 13).value = "最后做题时间"
if platform.system() == "Linux":
template_path = os.getcwd()
wb1.save(template_path+"/做题神器小程序——题库模板格式.xlsx")
elif platform.system() == "Windows":
wb1.save("D:/做题神器小程序——题库模板格式.xlsx")
template_path = "D:/"
else:
template_path = os.getcwd()
wb1.save(template_path+"/做题神器小程序——题库模板格式.xlsx")
window = tk.Tk()
window.title("做题神器")
window.geometry("1000x700")
title_label = tk.Label(window, height = 1, width=40, font="黑体 16", \
bg="steel blue", fg="light cyan", text="做题神器")
title_label.pack(anchor="center", fill="x", padx= 40, pady=10)
sep = ttk.Separator(window, orient="horizontal")
sep.pack(anchor = "nw", fill = "x", padx=40, pady=10)
path_frame = tk.Frame(window)
path_frame.pack(anchor = "center", fill = "x", padx=40, pady=10)
path_entry = tk.Entry(path_frame, width=40, font="宋体 12")
path_entry.grid(row=0, column=0, sticky="W", ipadx=5, ipady=5, padx=40, pady=10)
r = 0 #r是题目所在的行数
m = 0 #m是本次练习的题目数
i = 0 #i是todo_dict中题目的下标号
todo_dict = {} #待练题字典,r是键
todayYMD = dt.datetime.now().date()
print(todayYMD)
todo_list = []
def display_update():
if m % 20 == 0: #m是20的倍数时,刷新一下todo_dict
for r in range(2, nr):
if ws.cell(r, 11).value == None:
todo_dict[r] = "第一次做或一直没做对过"
elif ws.cell(r, 12).value == "Wr":
todo_dict[r] = "上次错"
elif ws.cell(r, 10).value != None and (ws.cell(r, 11).value != None) and \
(int(ws.cell(r, 10).value) > int(ws.cell(r, 11).value)):
todo_dict[r] = "错大于对"
elif ws.cell(r, 10).value != None and (ws.cell(r, 11).value != None) and \
int(ws.cell(r, 10).value) >=3 and (int(ws.cell(r, 11).value) < (3+ int(ws.cell(r, 10).value))):
todo_dict[r] = "错三次以上"
elif ws.cell(r, 13).value != None and \
(ws.cell(r, 13).value.date()< dt.datetime.now().date()-dt.timedelta(days=5)):
todo_dict[r] = "五天前做过"
elif ws.cell(r, 11).value != None and int(ws.cell(r, 11).value) <=2:
todo_dict[r] = "做对两遍以下的"
else:
pass
for k, v in todo_dict.items():
todo_list.append(k)
todo_list.sort() #改变原列表的排序
print(todo_list)
i = 0 #i归零
else:
pass
r = todo_list[i]
tigan_label.config(text = ws.cell(r, 1).value + " (" + ws.cell(r, 2).value + ") " + ws.cell(r, 3).value)
resp_label.config(text = todo_dict[r]) #显示该题的状态
if "判断" in ws.cell(r, 2).value:
xuanxiang_label.config(text="")
else:
xuanxiang_label.config(text="A、" + ws.cell(r, 5).value + "\n" + "B、" + ws.cell(r, 6).value + "\n" +\
"C、" + ws.cell(r, 7).value + "\n" +"D、" + ws.cell(r, 8).value)
def open_path():
tiku_path = fd.askopenfilename()
path_entry.insert(text=tiku_path)
wb = px.load_workbook(tiku_path)
ws = wb.active
nr = ws.max_row
display_update() #初始r=2
path_button = ttk.Button(path_frame, width=10, text="浏览", command=open_path)
path_button.grid(row=0, column=1, sticky="E", ipadx=5, ipady=5, padx=40, pady=10)
prob_left_label = tk.Label(window, fg = "red", font = "黑体 12", wraplength = 1000,\
width=80, text="请确保格式正确:A序号,B题型,C题干,\
D答案,E-H选项,J出错次数;K正确次数;L最后正误;M最后做题时间。题库模板格式见%s下" % template_path,\
justify = "left", anchor = "nw")
prob_left_label.pack(anchor = "nw", fill = "x", padx=40, pady=10)
sep = ttk.Separator(window, orient="horizontal")
sep.pack(anchor = "nw", fill = "x", padx=40, pady=10)
tigan_label = tk.Label(window, fg = "red", font = "宋体 12", \
width=80, wraplength = 1000, text="题干", justify = "left", anchor = "nw")
tigan_label.pack(anchor = "nw", fill = "x", padx=40, pady=10)
xuanxiang_label= tk.Label(window, fg = "red", font = "宋体 12", wraplength = 1000,\
width=80, height = 8, text="选项", justify = "left", anchor = "nw")
xuanxiang_label.pack(anchor = "nw", fill = "both", padx=40, pady=10)
sub_frame = tk.Frame(window)
sub_frame.pack(anchor = "nw", fill = "x", padx=40, pady=10)
answer_entry = tk.Entry(sub_frame, width=40, font="宋体 12")
answer_entry.grid(row=0, column=0, sticky="W", ipadx=5, ipady=5, padx=40, pady=10)
def zuoti():
dn = answer_entry.get()
ws.cell(r, 12).value = todayYMD #记下最后做题时间为今天
if dn == None:
resp_label.config(text="未作答,请输入你的答案……")
else:
if dn == str(ws.cell(r, 4).value):
ws.cell(r, 12).value = "Rt"
if ws.cell(r, 11).value == None:
ws.cell(r, 11).value = 1
else:
ws.cell(r, 11).value = int(ws.cell(r, 11).value) + 1
else:
ws.cell(r, 12).value = "Wr"
if ws.cell(r, 10).value == None:
ws.cell(r, 10).value = 1
else:
ws.cell(r, 10).value = int(ws.cell(r, 11).value) + 1
prob_left_label.config(text = "当前题库大约有%s道题,加油……" % str(nr))
i = i +1
m = m +1
display_update()
def zuoti_enter(ev=None):
zuoti()
answer_entry.bind("Return", zuoti_enter)
submit_button = ttk.Button(sub_frame, width=10, text="提交", command=zuoti)
submit_button.grid(row=0, column=1, sticky="W", ipadx=5, ipady=5, padx=40, pady=10)
def tuichu():
sys.exit()
window.destroy()
exit_button = ttk.Button(sub_frame, width=10, text="退出", command=tuichu)
exit_button.grid(row=0, column=2, sticky="E", ipadx=5, ipady=5, padx=40, pady=10)
sep = ttk.Separator(window, orient="horizontal")
sep.pack(anchor = "nw", fill = "x", padx=40, pady=10)
resp_label = tk.Label(window, fg = "red", font = "宋体 12", width=80, wraplength = 1000, \
text="对错", justify = "left", anchor = "nw")
resp_label.pack(anchor = "nw", fill = "x", padx=40, pady=10)
window.mainloop()
做题神器TK版
最新推荐文章于 2025-03-07 21:15:20 发布