一、创作思想(创作背景、目的和意义)
至今,新高考已经在 14 个省市实施,其中除浙江外的 13 个省份实施六选三,而六选三的时间一般在高一下学期期中考试以后,此时考生仍在学习相对简单的必修知识,对于高中六个等级考学科的认识还不够充分,不够到位,对自己的未来打算也并不特别明晰。因此,选科就成了新高考地区许多高一同学的一大难题。许多同学在选科的时候没有 合理评判自己的学习情况和未来打算,造成盲目选科,之后甚至还要转科或在报志愿的时候因为选科问题不能上自己心仪的专业,这对于学习的连续性和未来的发展是极其不利的。因此,做一个六选三评测系统来帮助同学们更好的选择自己的科目就尤为重要,单纯的成绩决定选科并不合理,用多个维度综合分析出考生适合选择哪个学科才是对考生最有利的方式,本作品的分析方式是用学科成绩,波动程度,学科倾向爱好以及意向专业四大模块综合分析。
二、演示视频
下面是新高考六选三智能评测系统的演示与介绍视频,较为全面的介绍了整个新高考六选三的智能评测系统,也对整个系统进行了演示,可以直观的看到运行效果,推荐大家观看一下。
三、软硬件清单
硬件:任意可运行Python的电脑
四、创作过程(运用了哪些技术或技巧完成主题创作,哪些是得意之处)
本程序采用模块化编程,通过自定义函数的方式对添加考试信息、修改考试信息、查看考试信息、设置学科倾向度、设置意向专业、查看使用说明、开始六选三评测七大功能分别定义函数,运行时只需调用相应的函数,逻辑清晰,直观易懂。
下面我将一一列举制作的步骤,对应步骤的目的和对应的流程图,流程图可以清晰直观的显示出制作的过程,应用到的算法等,因此选用这种方式而非文字描述。
步骤1 制作关于登录注册的部分
这个步骤有两个目的,一是为了保护用户的信息安全,避免任何人都能看到自己的信息(包括考试信息,学科倾向度信息和意向专业信息,下同。),再一个就是为了方便在一台电脑上对多个用户进行评测,用不同的账号密码区分不同的用户。

步骤2 制作关于字符串加密解密的内容
这个步骤主要是为了保障用户的信息安全,因为用户的账号密码均存储在txt文件中,任何人都可以打开,因此对用户的密码进行加密,需要时再解密。

步骤3 制作关于雷达图绘制的内容
这个步骤主要是为了绘制出综合评测结果的雷达图,便于用户直观的观看自己的评测结果。

步骤4 制作关于考试数据区分提取的内容
这个步骤主要是为了区分不同用户的信息,在每个账号登录后只能显示这个用户自己的信息

步骤5 制作计算成绩模块评分的内容
这个模块是第一个核心评测模块,结合用户的成绩高低和波动程度进行对于成绩方面的评测,成绩高低采用了加权平均数,对考试的重要程度和排名高低进行综合评测,而波动程度则采用加权方差进行计算。(之所以不用分数是害怕受到考试难度高低的影响),因为成绩的评测是较为复杂的,因此单列出来进行制作,让程序结构变得更加清晰易懂。

步骤6 制作添加考试信息模块
本模块的目的是收集到用户的考试信息,看似简单,只需要用到文件写入,但是需要对考试信息的合法性(合法不是合乎法律,是合乎正常的数据类型与长度,比如考试分数输入“abc”肯定不合适)进行验证,还需要格式化后再写入。

步骤7 制作设置学科倾向度/意向专业模块
其实这是两个不同的模块,但是因为他们的处理方式很相似,因此只用一张流程图就能说明白,和添加考试信息比较像,也需要进行数据合法验证和格式化,不再赘述。

步骤8 制作修改/删除/查看考试信息模块
一样,这里也是多个模块具有相同逻辑,实际上他们就是一套系统的不同特殊情况,删除就是把考试信息从数据文件中删掉,查看就是不修改信息,修改的逻辑是先删除考试信息再直接转入“添加考试信息”模块,这样可以减少代码量,复用,也体现出了模块化编程的好处。

步骤9 制作综合评测分数算法
这是整个程序最为核心的内容,根据不同的模式对考试信息进行综合评测,评测方式和依据请看图,不再赘述。

五、软件运行截图
具体的运行效果可看演示视频,这里只展示几张运行截图






六、实用性分析
下图为我在我校2019级高考考生(我校位于山东济南,采用3+3新高考模式)进行的抽样调查,受时间限制,样本量较小,但是可以发现,100%的考生可以通过本系统命中至少一门选课,而有95.24%的考生至少命中两门,全准率也达到了惊人的71.43%,因此可以充分证明本系统的评测方式比较科学,使用的算法可信度也很高,适合推广开来,辅助各新高考地区学生解决选科难题。

七、引用情况
本作品从思路设计到代码的编写以及 UI 的绘制均为个人独立完成。但是在制作的过程当中会遇到一些难以解决的问题或模块化的功能,可能会通过在网络上寻找资源的方式进行部分引用和参考,但均为小功能,现列举在下面。
[1] tkinter 的画布 canvas 绑定鼠标滚轮的方法:
https://www.zhihu.com/question/385891705
本部分运用于查看考试信息,将画布绑定滚轮可以直接用鼠标滚轮而不必拖动下滑栏,增加了用户舒适度
[2] 字符串的加密与解密:
https://blog.51cto.com/linuxshow/784239
本部分运用于登录与注册,将加密后的字符串存储到 txt 文件中可以增加用户安全,避免出现盗取账号等现象。
[3] python str.format 与制表符\t 关于中文对齐的细节问题:
https://blog.csdn.net/Excaliburrr/article/details/76794451?utm_source=app&app_version=4.5.2
本部分运用于查看考试信息,将中英文混合对齐可以增加美
观程度。
[4] python 简单雷达图绘制:
https://www.cnblogs.com/walkwaters/articles/12094284.html
[5] 部分 UI 模板使用的 PPT 模板:
[6] 部分返回图标等引用了阿里巴巴 ico 库内的图标:
[7] 字符串的全角与半角转换:
https://m.jb51.net/article/53903.htm
该部分运用于查看考试信息,中英文因为都是 1 个字符但是占位不同,因此需要将英文和数字转换为全角符号方便对齐。
八、源码及源文件下载
import numpy as np import matplotlib.pyplot as plt import matplotlib import tkinter as tk import tkinter.messagebox def on_closing(): global quit if tk.messagebox.askokcancel("退出", "确定要退出程序吗?"): window.destroy() quit = 1 def jiaMi( s , key ):#定义:对用户输入的明文密码进行加密 b = bytearray( str(s).encode("gbk") ) n = len(b) # 求出 b 的字节数 c = bytearray( n*2 ) j = 0 for i in range( 0, n ): b1 = b[i] b2 = b1 ^ key # b1 = b2^ key c1 = b2 % 16 c2 = b2 // 16 # b2= c2*16 + c1 c1 = c1 + 65 c2 = c2 + 65 # 由于c1,c2都是 0~15之间的数, # 加上65就变成了A-P 的字符的编码 c[j] = c1 c[j+1] = c2 j = j+2 return c.decode("gbk") def ffjiaMi( s, key ):#定义:对加密后的密码进行解密 c = bytearray( str(s).encode("gbk") ) n = len(c) # 求出 b 的字节数 if n % 2 != 0 : return "" n = n // 2 b = bytearray( n ) j = 0 for i in range( 0, n ): c1 = c[j] c2 = c[j+1] j = j+2 c1 = c1 - 65 c2 = c2 - 65 b2 = c2*16 + c1 b1 = b2^ key b[i]= b1 try: return b.decode("gbk") except: return "解密失败" def loginr():#定义:登录后将该账号的考试信息提取出的函数 file1 = open('test.txt', 'r')#打开数据存储文件 alltest = file1.read() alltest2 = alltest.split('\n') de_alltest = [] for i in alltest2: al = i.split(',') if al[-1] == l[0]:#对数据按照用户信息分类 al.pop()#临时文件内的考试信息是将用户信息的元素删除后的信息,避免用户名的存在出现问题 alltest1 = ','.join(al) de_alltest.append(alltest1) file = open('interim.txt', 'w')#将符合该用户信息的文件存储到一个临时文件中供程序未来调用 for i in de_alltest: file.write(i + '\n') file.close() def mult(all):#定义:根据用户的考试信息来计算用户的成绩综合得分的函数,内部填写的all是考试科目 d = 0#定义各类变量的初始值,因为这是局部变量,而且大多数数据没有实际意义,只是作为计算参数,因此只按照字母命名, e = 0 c = 0 h = 0 f = 0 g = 0 j = 0 k = 0 l = 0 for i in all:#计算考试次数 b = i.split(',') d = d + int(b[-1]) e = e + 1 for i in all:#计算加权平均排名比例,用于表示成绩在所有考生中的水平 b = i.split(',') a = (((int(b[-2]) / int(b[-3])) * int(b[-1]) / d) / 1) * 100#平均值=(比例*参数)/参数总数,参数是考生填写的考试重要程度 j = ((int(b[-2]) / int(b[-3])) * int(b[-1])) / d c = c + a k = k + j c = 100 - c for i in all:#计算加权方差,用于表示考试的波动程度 b = i.split(',') f = ((int(b[-2]) / int(b[-3])) - k) ** 2 g = g + f g = 100 - ((g / e)*1000)#因为计算后都是极小的小数,而且分数越小代表成绩越好,因此用该算法将分数扩大 l = g * 0.3 + c * 0.7#按照三七分的比例对综合分数进行计算 l = round(l,2)#保留两位小数 return l def draw(a,b,c,d,e,f):#定义:用于绘制最终评测结果的雷达图的函数,参数abcdef分别依次代表物化政史地生的综合得分 matplotlib.rcParams["font.family"] = "SimHei" matplotlib.rcParams["font.sans-serif"] = ["SimHei"] labels = np.array(["物理", "化学", "思政", "历史", "地理", "生物"])#绘制极坐标系 nAttr = 6 data = np.array([a, b, c, d, e, f])#将参数在极坐标系中标点 angles = np.linspace(0, 2 * np.pi, nAttr, endpoint=False) data = np.concatenate((data, [data[0]])) angles = np.concatenate((angles, [angles[0]]))#定义关于雷达图各点的变量 labels = np.concatenate((labels, [labels[0]])) fig = plt.figure(facecolor="white")#绘制一个白色的画布作为底板 plt.subplot(111, polar=True)#申明绘制的是极点图 plt.plot(angles, data, "bo-", color="g", linewidth=2)#绘制图形,填充颜色 plt.fill(angles, data, facecolor="g", alpha=0.25) plt.thetagrids(angles * 180 / np.pi, labels) plt.figtext(0.52, 0.90, "成绩分析图\n分析图已自动保存至根目录,也可以在窗口左下保存该分析图", ha="center") plt.grid(True) plt.savefig("成绩分析图.png")#保存图片,等待调用并展示 plt.show() key = 186 napa = [] login = '' a = 0 l = [] hobby3 =[] choices2 = '' xyz = [] cholie = '' quit = 0 re = 0 def setdenglu(): change_state() change_state1() global napa napa =[change_state(),change_state1()] global login ate = 0 # 定义登录部分循环执行的变量 while ate < 3: # 未登录成功就循环执行 global l allogin4 = [] l = napa if l != None and l != []: files = open('login.txt', 'r') allogin = files.read() allogin2 = allogin.split('\n') # 进入存储账号密码的程序调用,按照账号分割成列表 for i in allogin2: allogin3 = i.split(',') # 把一个账号的数据分割成列表 allogin4.append(allogin3) try: for j in allogin4: jiemi_j = ffjiaMi(str(j[1]), key) if l[0] == j[0] and l[1] == jiemi_j: # 账号和密码对应 global a a = 2 tk.messagebox.showinfo('提示', '登录成功,欢迎使用!') atest = 2 ate = 5 window.destroy() break else: atest = 1 if atest == 1: # 输入错误后弹出错误窗口 tk.messagebox.showerror('错误', '账号或密码错误,请检查后重新输入。') break except: tk.messagebox.showerror('错误', '账号或密码错误,请检查后重新输入。') break else: break def setzhuce(): change_state() change_state1() global napa napa = [str(change_state()), str(change_state1())] global login ate = 0 # 定义登录部分循环执行的变量 while ate < 3: # 未登录成功就循环执行 global l allogin4 = [] l = napa no = 0 if l != None: files = open('login.txt', 'r') allogin = files.read() allogin2 = allogin.split('\n') # 进入存储账号密码的程序调用,按照账号分割成列表 files.close() for i in allogin2: allogin3 = i.split(',') # 把一个账号的数据分割成列表 allogin4.append(allogin3) try: for j in allogin4: # 检测该账号在数据文件中是否存在,若存在则不予以注册 jiemi_j = ffjiaMi(str(j[1]), key) if l[0] == jiemi_j: no = 1 continue except: pass if ',' in l[0] or ',' in l[1] or l[0] == '' or l[1] == '': tk.messagebox.showerror('错误', '不合法的账号密码,账号密码中不允许出现“,”也不允许不填写,请重新输入。') break if l != None and no != 1: # 不存在且填写了内容则注册 l[1] = jiaMi(l[1], key) files = open('login.txt', 'a') l1 = ','.join(l) files.write(l1 + '\n') # 将注册的信息填入数据文件 files.close() global a a = 2 tk.messagebox.showinfo('提示', '注册成功,欢迎使用!第一次使用请看使用说明。') window.destroy() break else: tk.messagebox.showerror('错误', '账号已被注册过,请重新输入。') break else: break def change_state(): var = l11.get() # 调用get()方法,将Entry中的内容获取出来 return var def change_state1(): var1 = l22.get() # 调用get()方法,将Entry中的内容获取出来 return var1 def back(): global window window.destroy() #窗口变量 window = tk.Tk() #窗口标题 window.title('请登录') #窗口大小 window.geometry('600x357') #画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=768, width=1024) #加载图片2 button_img_gif = tk.PhotoImage(file = 'b.png') button_img = tk.Button(canvas, image = button_img_gif, height=28, width=180,text = '带图按钮',bg='black',command=setzhuce) button_img.place(x=80,y=217) button_img_gif1 = tk.PhotoImage(file = 'f.png') button_img1 = tk.Button(canvas, image = button_img_gif1, height=28, width=180,text = '带图按钮',bg='black',command=setdenglu) button_img1.place(x=80,y=270) #加载图片1 image_file = tk.PhotoImage(file='d.png') #定义图片2的位置 image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack() #定义图片1的位置 #image1 = canvas.create_arc(55, 230, anchor='nw', image=button_img_gif ) new_name=tk.StringVar() l11 = tk.Entry(canvas,textvariable=new_name,font =('微软雅黑',14)) l11.place(x=120,y=97,width=150, height=35) #密码变量及标签、输入框 new_pwd=tk.StringVar() l22 = tk.Entry(canvas,textvariable=new_pwd,show='*',font =('微软雅黑',14)) l22.place(x=120,y=157,width=150, height=35) #程序 window.mainloop() def get(c): d = c.get() return d while 1 < a < 3: # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请选择您要进行的操作') # 窗口大小 window.geometry('800x434') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=434, width=800) def addtest(): global window window.destroy() testvalues = [] testwhile = 0 # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请填写要添加的考试信息') # 窗口大小 window.geometry('826x472') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=472, width=826) # 加载图片2 # 加载图片1 image_file = tk.PhotoImage(file='测试1.png') # 定义图片2的位置 image = canvas.create_image(0, 0, anchor='nw', image=image_file) new_pwd = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd,font =('微软雅黑',12)) l1.place(x=331, y=24, width=334, height=30) new_pwd1 = tk.StringVar() l2 = tk.Entry(canvas, textvariable=new_pwd1,font =('微软雅黑',12)) l2.place(x=380, y=89, width=360, height=30) new_pwd2 = tk.StringVar() l3 = tk.Entry(canvas, textvariable=new_pwd2,font =('微软雅黑',12)) l3.place(x=360, y=163, width=300, height=30) new_pwd3 = tk.StringVar() l4 = tk.Entry(canvas, textvariable=new_pwd3,font =('微软雅黑',12)) l4.place(x=380, y=236, width=360, height=30) new_pwd4 = tk.StringVar() l5 = tk.Entry(canvas, textvariable=new_pwd4,font =('微软雅黑',12)) l5.place(x=360, y=318, width=300, height=30) new_pwd5 = tk.StringVar() l6 = tk.Entry(canvas, textvariable=new_pwd5,font =('微软雅黑',12)) l6.place(x=420, y=387, width=300, height=30) def dengji(): testvalues = [str(get(new_pwd)), str(get(new_pwd1)), str(get(new_pwd2)), str(get(new_pwd3)), str(get(new_pwd4)), str(get(new_pwd5))] global testwhile testwhile = 0 try: if testvalues != None: # 检测考试信息是否符合填写要求,若符合执行添加,不符合执行错误提示 for i in testvalues[3:4]: # 对于数据类型的检索 i = float(i) testvalues[2] = int(testvalues[2]) testvalues[2] = str(testvalues[2]) if len(testvalues[0]) > 6: # 对于长度的检索 testwhile = 1 if len(testvalues[1]) > 2: testwhile = 1 if int(testvalues[5]) > 10: testwhile = 1 if len(testvalues[3]) > 4: testwhile = 1 if len(testvalues[4]) > 4: testwhile = 1 if testwhile == 1: # 错误提示 tk.messagebox.showerror('错误', '输入格式错误,\n考试名称最多6个字,考试科目最多2个字,\n分数只允许输入整数或小数,总人数和排名只允许输入整数且重要程度只允许输入0-10之中的整数,请检查后重新输入。') elif testwhile != 1: print(l[0]) testvalues.append(str(l[0])) if type(testvalues) == list: # 正确,将取出的列表用“,”分割开,然后存入数据文件再回车,方便区分不同的考试信息 alltest1 = ','.join(testvalues) file = open('test.txt', 'a') file.write(alltest1 + '\n') file.close() loginr() global window global re tk.messagebox.showinfo('提示', '考试信息添加成功!') re = 1 window.destroy() except: # 错误提示 tk.messagebox.showerror('错误','输入格式错误,考试名称最多6个字,考试科目最多2个字,分数,总人数和排名只允许输入整数或小数,请检查后重新输入。') testwhile = 1 button_img_gif = tk.PhotoImage(file='确定1.png') button_img = tk.Button(canvas, image=button_img_gif, text='带图按钮', height=32, width=32,command = dengji) button_img.place(x=370, y=426) button_img_gif1 = tk.PhotoImage(file='取消1.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=32, width=32,command = back) button_img1.place(x=410, y=426) canvas.pack() # 程序 window.mainloop() def addlove(): global window window.destroy() # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请填写您的学科倾向度') # 窗口大小 window.geometry('836x477') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=477, width=836) # 加载图片2 # 加载图片1 image_file3 = tk.PhotoImage(file='设置学科倾向ui.png') # 定义图片2的位置 image = canvas.create_image(0, 0, anchor='nw', image=image_file3) new_pwd11 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd11,font =('微软雅黑',12)) l1.place(x=741, y=124, width=30, height=30) new_pwd12 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd12,font =('微软雅黑',12)) l1.place(x=530, y=119, width=30, height=30) new_pwd13 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd13,font =('微软雅黑',12)) l1.place(x=366, y=206, width=25, height=25) new_pwd14 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd14,font =('微软雅黑',12)) l1.place(x=740, y=366, width=30, height=30) new_pwd15 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd15,font =('微软雅黑',12)) l1.place(x=280, y=338, width=30, height=30) new_pwd16 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd16,font =('微软雅黑',12)) l1.place(x=570, y=389, width=30, height=30) def adlove(): hobby1 = [str(get(new_pwd15)), str(get(new_pwd11)), str(get(new_pwd14)), str(get(new_pwd13)), str(get(new_pwd12)), str(get(new_pwd16))] hobbywhile = 0 try: # 检测偏好度信息是否符合填写要求,若符合执行添加,不符合执行错误提示 if hobby1 != None: for i in hobby1: i = int(i) # 检测数据类型 if i < 100: # 检测数据范围 hobbywhile = 0 global window tk.messagebox.showinfo('提示', '倾向度信息添加成功!') window.destroy() break else: hobbywhile = 1 tk.messagebox.showerror('错误','输入错误,各科都必须填写且只允许输入0-100的整数,请检查后重新输入。') break except: tk.messagebox.showerror('错误','输入错误,各科都必须填写且只允许输入0-100的整数,请检查后重新输入。') # 输出错误信息 hobbywhile = 1 if type(hobby1) == list and hobbywhile != 1: # 如果hobby1类型正常且里面内容的类型正常则进行添加机制 ij = 0 hobby1 = ','.join(hobby1) hobby1s = f'{hobby1},{l[0]}' # 将信息转化为字符串格式并添加用户名参数 file4 = open('test1.txt', 'r') # 将信息存入数据文件 hobby = file4.read() hobby2 = hobby.split('\n') if '' in hobby2: hobby2.remove('') # 删除因回车造成的空字符串 ij = ij + 1 for i in hobby2: j = i.split(',') if j[-1] == l[0]: # 检测用户名数据相符则先删除之前的偏好度信息再添加新的偏好度信息 hobby2.remove(i) # 删 ij = ij + 1 hobby2.append(hobby1s) # 增 if ij == 1: hobby2.append(hobby1s) file4 = open('test1.txt', 'w') for i in hobby2: i = f'{i}\n' file4.write(i) # 将信息写入数据文件 file4.close() button_img_gif = tk.PhotoImage(file='确定1.png') button_img = tk.Button(canvas, image=button_img_gif, text='带图按钮', height=32, width=32,command = adlove) button_img.place(x=370, y=426) def back(): global window window.destroy() button_img_gif1 = tk.PhotoImage(file='取消1.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=32, width=32,command = back) button_img1.place(x=410, y=426) canvas.pack() def seelove(): global l file4 = open('test1.txt', 'r') # 打开存储偏好度的文件并读取 global hobby3 hobby = file4.read() hobby2 = hobby.split('\n') # 将所有用户的信息都读出并分割,让每个元素代表一个用户的偏好度信息 for i in hobby2: j = i.split(',') if j[-1] == l[0]: # 读取该用户的偏好度信息 hobby3 = j file4.close() if hobby3 == []: # 若从未填写过则显示未设置 hobby3 = ['未设置', '未设置', '未设置', '未设置', '未设置', '未设置'] tk.messagebox.showinfo('查看',f"这里是您已经设置过的学科偏好度,若需修改请重新输入您的学科偏好度(1-100的整数)\n您的物理偏好度是{hobby3[0]};" f"\n您的化学偏好度是{hobby3[1]};\n您的生物偏好度是{hobby3[2]};\n您的思政偏好度是{hobby3[3]};\n您的历史偏好度是{hobby3[4]};" f"\n您的地理偏好度是{hobby3[5]}。") button_img_gif3 = tk.PhotoImage(file='记录1.png') button_img2 = tk.Button(canvas, image=button_img_gif3, text='带图按钮', height=57, width=57, command=seelove) button_img2.place(x=100, y=400) # 程序 window.mainloop() def setmajor(): global window window.destroy() def addmajor(): global choice3 global l if choice3[0] != 'N': file4 = open('test2.txt', 'r') cho = file4.read() cho2 = cho.split('\n') ji = 0 for i in cho2: j = i.split(',') if j[-1] == l[0]: cho2.remove(i) # 检测用户名数据相符则先删除之前的专业信息再添加新的专业信息 if '' in cho2: cho2.remove('') # 删除因回车造成的空字符串 cho2.append(choice3) ji = ji + 1 if ji == 0: cho2.append(choice3) file4 = open('test2.txt', 'w') for i in cho2: i = f'{i}\n' file4.write(i) # 将信息写入数据文件 file4.close() tk.messagebox.showinfo('提示', '意向专业设置成功!') def history(): global choice2 global choice3 choice2 = '历史学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def medical(): global choice2 global choice3 choice2 = '医学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def literature(): global choice2 global choice3 choice2 = '文学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def agronomy(): global choice2 global choice3 choice2 = '农学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def education(): global choice2 global choice3 choice2 = '教育学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def industry(): global choice2 global choice3 choice2 = '工学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def law(): global choice2 global choice3 choice2 = '法学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def economy(): global choice2 global choice3 choice2 = '经济学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def philosophy(): global choice2 global choice3 choice2 = '哲学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def math(): global choice2 global choice3 choice2 = '理学' choice3 = f'{choice2},{l[0]}\n' # 将数据添加用户名参数并回车,方便下次存入 addmajor() def seemajor(): global l file5 = open('test2.txt', 'r') choices2 = file5.read() # 从专业选择文件中提取全部用户的信息并进行检索,检索到该用户信息则存入choice2变量里 choice2 = choices2.split('\n') for i in choice2: j = i.split(',') if j[-1] == l[0] and j[0] != None: choice2 = j[0] file5.close() if len(str(choice2)) > 4: de_choice2 = '从未设置' else: de_choice2 = choice2 tk.messagebox.showinfo('查看',f"这里是您曾经选择过的意向专业所在的大类,若需修改请重新选择:\n{de_choice2}") # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请选择您的意向专业') # 窗口大小 window.geometry('844x458') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=458, width=844) # 加载图片2 button_img_gif = tk.PhotoImage(file='历史学.png') button_img = tk.Button(canvas, image=button_img_gif, text='带图按钮', height=32, width=109, bd = 0,bg='#003366',command = history) button_img.place(x=197, y=82) button_img_gif1 = tk.PhotoImage(file='医学.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=32, width=119, bd = 0,bg='#003366',command = medical) button_img1.place(x=525, y=84) button_img_gif2 = tk.PhotoImage(file='农学.png') button_img2 = tk.Button(canvas, image=button_img_gif2, text='带图按钮', height=32, width=159,bd = 0, bg='#246A9C',command = literature) button_img2.place(x=525, y=148) button_img_gif3 = tk.PhotoImage(file='文学.png') button_img3 = tk.Button(canvas, image=button_img_gif3, text='带图按钮', height=32, width=154,bd = 0, bg='#246A9C',command = agronomy) button_img3.place(x=152, y=146) button_img_gif4 = tk.PhotoImage(file='教育学.png') button_img4 = tk.Button(canvas, image=button_img_gif4, text='带图按钮', height=32, width=185, bd = 0,bg='#003366',command = education) button_img4.place(x=122, y=208) button_img_gif5 = tk.PhotoImage(file='工学.png') button_img5 = tk.Button(canvas, image=button_img_gif5, text='带图按钮', height=32, width=185,bd = 0, bg='#003366',command = industry) button_img5.place(x=525, y=208) button_img_gif6 = tk.PhotoImage(file='经管学.png') button_img6 = tk.Button(canvas, image=button_img_gif6, text='带图按钮', height=32, width=159,bd = 0, bg='#246A9C',command = law) button_img6.place(x=525, y=272) button_img_gif7 = tk.PhotoImage(file='法学.png') button_img7 = tk.Button(canvas, image=button_img_gif7, text='带图按钮', height=32, width=154, bd = 0,bg='#246A9C',command = economy) button_img7.place(x=152, y=270) button_img_gif8 = tk.PhotoImage(file='哲学.png') button_img8 = tk.Button(canvas, image=button_img_gif8, text='带图按钮', height=32, width=119, bd = 0,bg='#003366',command = philosophy) button_img8.place(x=187, y=332) button_img_gif9 = tk.PhotoImage(file='理学.png') button_img9 = tk.Button(canvas, image=button_img_gif9, text='带图按钮', height=32, width=109, bd = 0,bg='#003366',command = math) button_img9.place(x=525, y=334) button_img_gif33 = tk.PhotoImage(file='记录1.png') button_img33 = tk.Button(canvas, image=button_img_gif33, text='带图按钮', height=57, width=57, command=seemajor) button_img33.place(x=310, y=388) button_img_gif11 = tk.PhotoImage(file='取消1.png') button_img11 = tk.Button(canvas, image=button_img_gif11, text='带图按钮', height=32, width=32,command = back) button_img11.place(x=410, y=416) canvas.pack() image_file = tk.PhotoImage(file='专业UI.png') image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack() # 程序 window.mainloop() def inst(): def go(): global window window.destroy() # 窗口变量 window = tk.Tk() # 窗口标题 window.title('使用说明 第2页') # 窗口大小 window.geometry('948x520') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=520, width=948) button_img_gif31 = tk.PhotoImage(file='后退.png') button_img31 = tk.Button(canvas, image=button_img_gif31, text='带图按钮', height=40, width=40, command=gone) button_img31.place(x=480, y=466) button_img_gif32 = tk.PhotoImage(file='返回1.png') button_img32 = tk.Button(canvas, image=button_img_gif32, text='带图按钮', height=40, width=40, command=back) button_img32.place(x=430, y=466) canvas.pack() canvas.pack() image_file = tk.PhotoImage(file='说明2.png') image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack() window.mainloop() def gone(): global window window.destroy() # 窗口变量 window = tk.Tk() # 窗口标题 window.title('使用说明 第1页') # 窗口大小 window.geometry('948x520') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=520, width=948) button_img_gif11 = tk.PhotoImage(file='前进1.png') button_img11 = tk.Button(canvas, image=button_img_gif11, text='带图按钮', height=40, width=40, command=go) button_img11.place(x=480, y=466) canvas.pack() button_img_gif12 = tk.PhotoImage(file='返回1.png') button_img12 = tk.Button(canvas, image=button_img_gif12, text='带图按钮', height=40, width=40, command=back) button_img12.place(x=430, y=466) canvas.pack() image_file = tk.PhotoImage(file='说明1.png') image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack() # 程序 window.mainloop() gone() def seescore(): global window window.destroy() prin1 = '' prinr = ['考试名称 考试科目 得分 总人数 排名 重要度 '] def processWheel(event): a = int(-(event.delta) / 60) c.yview_scroll(a, 'units') def strB2Q(ustring): """半角转全角""" rstring = "" for uchar in ustring: inside_code = ord(uchar) if inside_code == 32: # 半角空格直接转化 inside_code = 12288 elif inside_code >= 32 and inside_code <= 126: # 半角字符(除空格)根据关系转化 inside_code += 65248 rstring += chr(inside_code) return rstring loginr() file1 = open('interim.txt', 'r') # 从临时文件中调取已登录用户的数据,并进行显示 alltes = file1.read() alltes2 = alltes.split('\n') test1 = '' for i in alltes2: alltes3 = i.split(',') alltes3[0] = strB2Q(str(alltes3[0])) try: prin = '{name:<{len}}\t{name1:<{len1}}\t{name2:<{len1}}\t{name3:<{len1}}\t{name4:<{len1}}\t{name5:<{len1}}'.format( name=alltes3[0], name1=alltes3[1], name2=alltes3[2], name3=alltes3[3], name4=alltes3[4], name5=alltes3[5], len1=10 - len(alltes3[1].encode('GB2312')) + len(alltes3[1]), len=16 - len(alltes3[1].encode('GB2312')) + len(alltes3[1])) prinr.append(prin) prin1 = '\n'.join(prinr) except: pass window = tk.Tk(className='请查看您曾经添加的考试信息') scrollbar = tk.Scrollbar(window) c = tk.Canvas(window, background="#42586E", yscrollcommand=scrollbar.set, width=770, height=800) scrollbar.config(command=c.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) c.pack(side="left", fill="both", expand=True) f = tk.Frame(c) c.create_window(0, 0, window=f, anchor='nw') button_img_gif11 = tk.PhotoImage(file='返回1.png') button_img11 = tk.Button(c, image=button_img_gif11, text='带图按钮', height=40, width=40,command=back) button_img11.place(x=710, y=38) label = tk.Label(f, wraplength=840, text=prin1, font=('微软雅黑', 18), fg="#E3D4AF", bg='#42586E', anchor='w') label.bind("<MouseWheel>", processWheel) label.pack() window.update() c.config(scrollregion=c.bbox("all")) f.bind("<MouseWheel>", processWheel) c.bind("<MouseWheel>", processWheel) c.pack() window.mainloop() def evaluation(): global window window.destroy() # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请选择您的考试方案和测评模式') # 窗口大小 window.geometry('924x469') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=469, width=924) def watch3(): global allscores global window # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请查看您的六选三分析报告') # 窗口大小 window.geometry('886x457') photo = tk.PhotoImage(file='测评结果分析.png') the_label = tk.Label(window, text=allscores, # 字符串进行左对齐 image=photo, compound='center', # 混合模式,文字在图片的正上方显示 font=("微软雅黑", 16), # 字体和大小 fg='black'# 前景颜色,就是字体颜色 ) the_label.pack() # 这句不可少呀 window.mainloop() def start(): try: global allscores major_p = 0 # 初始化各个学科的专业偏重分数为0分 major_c = 0 major_h = 0 major_g = 0 major_o = 0 major_b = 0 file5 = open('test2.txt', 'r') # 将用户的专业信息调取出来并存入choice2变量 choices2 = file5.read() choice2 = choices2.split('\n') for i in choice2: j = i.split(',') if j[-1] == l[0]: choice2 = j[0] file5.close() # 以下的都是各个专业对应的专业偏重分数并赋值到学科中,值越高代表选择该学科对报这个专业越不会被限制,100即为完全不会被限制,1-99为部分学校或该大类下的部分专业有限制,0即为选择该学科不会对该大类下的专业有帮助,数据来源于2020各高校的选科要求 # 用户对这些信息没有了解的必要,各个学科的专业偏重分数仅作为后端信息用于综合分数的计算。 if choice2 == '教育学' or choice2 == '经济学' or choice2 == '文学' or choice2 == '哲学': major_p = 100 major_c = 100 major_h = 100 major_g = 100 major_o = 100 major_b = 100 elif choice2 == '历史学': major_h = 100 major_g = 70 elif choice2 == '管理学': major_p = 100 major_c = 75 major_h = 75 major_g = 75 major_o = 75 major_b = 75 elif choice2 == '工学': major_p = 100 major_c = 75 elif choice2 == '医学': major_b = 75 major_c = 100 major_p = 35 elif choice2 == '理学': major_c = 75 major_p = 100 major_b = 40 major_g = 15 major_h = 10 major_o = 10 elif choice2 == '农学': major_b = 100 major_c = 100 major_p = 55 elif choice2 == '法学': major_h = 70 major_g = 70 major_o = 100 x = float(xyz[0]) y = float(xyz[1]) z = float(xyz[2]) # 检测数据类型 if x + y + z == 1 and x >= 0 and y >= 0 and z >= 0: # 检测数据范围 modetest = 0 else: modetest = 1 if modetest == 0: phy = [] # 初始化各个学科的总列表为空列表 che = [] his = [] bio = [] geo = [] pol = [] tec = [] file1 = open('interim.txt', 'r') # 读取临时文件中本用户的全部考试并进行分割 alltest = file1.read() alltest2 = alltest.split('\n') for i in alltest2: p = i.find('物理') # 对每条考试信息进行科目检索,检索到对应科目后将该条信息加入到本科目的总列表中去 c = i.find('化学') h = i.find('历史') b = i.find('生物') g = i.find('地理') o = i.find('思政') t = i.find('技术') if p != -1: phy.append(i) elif c != -1: che.append(i) elif h != -1: his.append(i) elif b != -1: bio.append(i) elif g != -1: geo.append(i) elif o != -1: pol.append(i) elif t != -1: tec.append(i) file4 = open('test1.txt', 'r') # 调取全部用户的学科偏好度信息并选出本用户的信息,存入hobby3列表参与计算 hobby3 = [] hobby = file4.read() hobby2 = hobby.split('\n') for i in hobby2: j = i.split(',') if j[-1] == l[0]: # 选取本用户 hobby3 = j file4.close() # 将对应的三个参考值乘以对应比例数值(之前已定义)并计算出各科的综合评分 p_score = mult(phy) * x + major_p * y + float(hobby3[0]) * z c_score = mult(che) * x + major_c * y + float(hobby3[1]) * z h_score = mult(his) * x + major_h * y + float(hobby3[4]) * z b_score = mult(bio) * x + major_b * y + float(hobby3[2]) * z g_score = mult(geo) * x + major_g * y + float(hobby3[5]) * z o_score = mult(pol) * x + major_o * y + float(hobby3[3]) * z p_score = round(p_score, 2) # 对综合评分保留两位小数 c_score = round(c_score, 2) h_score = round(h_score, 2) b_score = round(b_score, 2) g_score = round(g_score, 2) o_score = round(o_score, 2) draw(p_score, c_score, o_score, h_score, g_score, b_score) # 绘制雷达图,具体的见上文 allscore = {'物理': p_score, "化学": c_score, '历史': h_score, '地理': g_score, '思政': o_score, '生物': b_score} # 设置字典,令综合评分和学科一一对应起来,参与输出 global cholie if cholie == '3+3': allscore_order = sorted(allscore.items(), key=lambda x: x[1], reverse=True) # 对全部学科的综合评分进行倒序排序,使输出更直观 allscores = f'\n\n您的{allscore_order[0][0]}评测分数是{allscore_order[0][1]};\n您的{allscore_order[1][0]}评测分数是{allscore_order[1][1]};\n' \ f'您的{allscore_order[2][0]}评测分数是{allscore_order[2][1]};\n您的{allscore_order[3][0]}评测分数是{allscore_order[3][1]};\n' \ f'您的{allscore_order[4][0]}评测分数是{allscore_order[4][1]};\n您的{allscore_order[5][0]}评测分数是{allscore_order[5][1]}。\n\n' \ f'因此推荐您选择{allscore_order[0][0]}、{allscore_order[1][0]}、{allscore_order[2][0]}作为您的等级考学科\n评测结果仅供参考,请理性选科,为自己的未来负责。' watch3() elif cholie == '3+1+2': if h_score > p_score: shouxuan = '历史' else: shouxuan = '物理' del allscore['物理'] del allscore['历史'] cixuan = sorted(allscore.items(), key=lambda x: x[1], reverse=True) allscores = f'\n首选科目评测:\n您的历史评测分数是{h_score};\n您的物理评测分数是{p_score};\n' \ f'再选科目评测:\n您的{cixuan[0][0]}评测分数是{cixuan[0][1]};\n您的{cixuan[1][0]}评测分数是{cixuan[1][1]};\n' \ f'您的{cixuan[2][0]}评测分数是{cixuan[2][1]};\n您的{cixuan[3][0]}评测分数是{cixuan[3][1]}。\n' \ f'因此推荐您选择{shouxuan}、{cixuan[0][0]}、{cixuan[1][0]}作为您的等级考学科\n评测结果仅供参考,请理性选科,为自己的未来负责。' # 输出参数 watch3() else: # 格式错误则输出错误信息 tk.messagebox.showerror('错误', '输入错误,只允许输入0-1的小数且三项总和须恰好为1,请检查后重新输入。') # 输出错误信息 except:#格式错误则输出错误信息 tk.messagebox.showerror('错误', '输入格式错误或各项信息未填写完全,比例只允许输入0-1的小数且三项总和须恰好为1,各科均需要添加至少一次考试且必须选择好意向专业并填写学科倾向,请检查后重新输入。') # 输出错误信息 def cholie1(): global cholie cholie = '3+3' tk.messagebox.showinfo('提示', '您已将测评模式设置为”3+3“。') def cholie2(): global cholie cholie = '3+1+2' tk.messagebox.showinfo('提示', '您已将测评模式设置为”3+1+2“') def moto(): global cholie global xyz x = 0.65 y = 0.2 z = 0.15 xyz = [x, y, z] if cholie != '': global window window.destroy() start() else: tk.messagebox.showerror('错误', '请先设置“3+3”或“3+1+2”模式后再进行测评') return xyz def major(): global cholie global xyz x = 0.2 y = 0.6 z = 0.2 xyz = [x, y, z] if cholie != '': global window window.destroy() start() else: tk.messagebox.showerror('错误', '请先设置“3+3”或“3+1+2”模式后再进行测评') return xyz def inte(): global cholie global xyz x = 0.2 y = 0.2 z = 0.6 xyz = [x, y, z] if cholie != '': global window window.destroy() start() else: tk.messagebox.showerror('错误', '请先设置“3+3”或“3+1+2”模式后再进行测评') return xyz def score(): global cholie global xyz x = 0.8 y = 0.1 z = 0.1 xyz = [x, y, z] if cholie != '': global window window.destroy() start() else: tk.messagebox.showerror('错误', '请先设置“3+3”或“3+1+2”模式后再进行测评') return xyz def self(): if cholie != '': global window window.destroy() # 窗口变量 window = tk.Tk() # 窗口标题 window.title('请填写您的测评比例') # 窗口大小 window.geometry('477x552') # 画布大小设置,白色背景1024*768 canvas = tk.Canvas(window, bg='white', height=552, width=477) # 加载图片2 # 加载图片1 image_file3 = tk.PhotoImage(file='自定义比例 UI.png') # 定义图片2的位置 image = canvas.create_image(0, 0, anchor='nw', image=image_file3) new_pwd11 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd11, font=('微软雅黑', 12)) l1.place(x=384, y=424, width=29, height=23) new_pwd12 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd12, font=('微软雅黑', 12)) l1.place(x=74, y=369, width=38, height=30) new_pwd13 = tk.StringVar() l1 = tk.Entry(canvas, textvariable=new_pwd13, font=('微软雅黑', 12)) l1.place(x=350, y=206, width=29, height=25) def adbi(): global xyz xyz = [str(get(new_pwd12)), str(get(new_pwd13)), str(get(new_pwd11))] global window window.destroy() start() button_img_gif = tk.PhotoImage(file='确定1.png') button_img = tk.Button(canvas, image=button_img_gif, text='带图按钮', height=32, width=32, command=adbi) button_img.place(x=370, y=486) button_img_gif1 = tk.PhotoImage(file='取消1.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=32, width=32, command=back) button_img1.place(x=410, y=486) canvas.pack() canvas.pack() window.mainloop() else: tk.messagebox.showerror('错误', '请先设置“3+3”或“3+1+2”模式后再进行测评') # 加载图片2 button_img_gif = tk.PhotoImage(file='自动设置.png') button_img = tk.Button(window, image=button_img_gif, text='带图按钮', height=137, width=132, bd = 0,command=moto) button_img.place(x=48, y=274) button_img_gif1 = tk.PhotoImage(file='多参考专业.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=137, width=137,bd = 0, command=major) button_img1.place(x=562, y=178) button_img_gif2 = tk.PhotoImage(file='多参考兴趣.png') button_img2 = tk.Button(canvas, image=button_img_gif2, text='带图按钮', height=137, width=137,bd = 0, command=inte) button_img2.place(x=220, y=176) button_img_gif3 = tk.PhotoImage(file='多参考成绩.png') button_img3 = tk.Button(canvas, image=button_img_gif3, text='带图按钮', height=139, width=139,bd = 0, command=score) button_img3.place(x=389, y=274) button_img_gif4 = tk.PhotoImage(file='自定义比例.png') button_img4 = tk.Button(canvas, image=button_img_gif4, text='带图按钮', height=137, width=137, bd = 0,command=self) button_img4.place(x=736, y=273) button_img_gif5 = tk.PhotoImage(file='3+3.png') button_img5 = tk.Button(canvas, image=button_img_gif5, text='带图按钮', bd = 0,bg ='#FDFDFD',height=132, width=132, command=cholie1) button_img5.place(x=281, y=42) button_img_gif6 = tk.PhotoImage(file='3+1+2.png') button_img6 = tk.Button(canvas, image=button_img_gif6, text='带图按钮',bd = 0,bg ='#FDFDFD', height=132, width=132, command=cholie2) button_img6.place(x=470, y=42) image_file = tk.PhotoImage(file='开始测评.png') image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack() # 程序 window.mainloop() def modify(): global window window.destroy() prin1 = '' prinr = [ '\n\n\n\n\n请在上面的框中依次按顺序输入要修改的原错误考试信息\n信息可在下面查阅,输入好后单击“修改”或“删除”\n考试名称 考试科目 得分 总人数 排名 重要度 '] loginr() file1 = open('test.txt', 'r') # 从数据文件中提取全部数据,目的是未来要添加新的考试 alltest = file1.read() alltest2 = alltest.split('\n') interfile1 = open('interim.txt', 'r') # 提取用户的信息 interalltest = interfile1.read() interalltest2 = interalltest.split('\n') def get(c): d = c.get() return d def delete(): global l global change change = [str(get(new_pwd)), str(get(new_pwd1)), str(get(new_pwd2)), str(get(new_pwd3)), str(get(new_pwd4)), str(get(new_pwd5))] change1 = ','.join(change) changes = f'{change1},{l[0]}' # 将change添加用户的用户名参数 if change1 in interalltest2: # 在列表中删除用户的选择 alltest2.remove(changes) file3 = open('test.txt', 'w') # 打开数据文件,将删除后的数据重新填入数据文件 for i in alltest2: file3.write(i + '\n') file3.close() interalltest2.remove(change1) interfile3 = open('interim.txt', 'w') # 打开临时文件,将删除后的数据填入临时文件 for i in interalltest2: interfile3.write(i + '\n') interfile3.close() loginr() tk.messagebox.showinfo('提示', '考试信息删除成功!回到主页后再次进入即可更新到删除后的全部考试信息。') else: tk.messagebox.showerror('错误', '输入内容有误,在您之前添加的考试信息中未找到该条考试,请检查后重试') def revise(): global l global change global re change = [str(get(new_pwd)), str(get(new_pwd1)), str(get(new_pwd2)), str(get(new_pwd3)), str(get(new_pwd4)), str(get(new_pwd5))] change1 = ','.join(change) interfile1 = open('interim.txt', 'r') # 提取用户的信息 interalltest = interfile1.read() interalltest2 = interalltest.split('\n') if change1 in interalltest2: change = [str(get(new_pwd)), str(get(new_pwd1)), str(get(new_pwd2)), str(get(new_pwd3)), str(get(new_pwd4)), str(get(new_pwd5))] change1 = ','.join(change) changes = f'{change1},{l[0]}' # 将change添加用户的用户名参数 if change1 in interalltest2: # 在列表中删除用户的选择 alltest2.remove(changes) file3 = open('test.txt', 'w') # 打开数据文件,将删除后的数据重新填入数据文件 for i in alltest2: file3.write(i + '\n') file3.close() interalltest2.remove(change1) interfile3 = open('interim.txt', 'w') # 打开临时文件,将删除后的数据填入临时文件 for i in interalltest2: interfile3.write(i + '\n') interfile3.close() loginr() tk.messagebox.showinfo('提示', '原考试信息已成功删除,请单击确定键新增修改后的考试!') else: tk.messagebox.showerror('错误', '输入内容有误,在您之前添加的考试信息中未找到该条考试,请检查后重试') addtest() else: tk.messagebox.showerror('错误', '输入内容有误,在您之前添加的考试信息中未找到该条考试,请检查后重试') def processWheel(event): a = int(-(event.delta) / 60) c.yview_scroll(a, 'units') def strB2Q(ustring): """半角转全角""" rstring = "" for uchar in ustring: inside_code = ord(uchar) if inside_code == 32: # 半角空格直接转化 inside_code = 12288 elif inside_code >= 32 and inside_code <= 126: # 半角字符(除空格)根据关系转化 inside_code += 65248 rstring += chr(inside_code) return rstring file1 = open('interim.txt', 'r') # 从临时文件中调取已登录用户的数据,并进行显示 alltes = file1.read() alltes2 = alltes.split('\n') test1 = '' for i in alltes2: alltes3 = i.split(',') alltes3[0] = strB2Q(str(alltes3[0])) try: prin = '{name:<{len}}\t{name1:<{len1}}\t{name2:<{len1}}\t{name3:<{len1}}\t{name4:<{len1}}\t{name5:<{len1}}'.format( name=alltes3[0], name1=alltes3[1], name2=alltes3[2], name3=alltes3[3], name4=alltes3[4], name5=alltes3[5], len1=10 - len(alltes3[1].encode('GB2312')) + len(alltes3[1]), len=16 - len(alltes3[1].encode('GB2312')) + len(alltes3[1])) prinr.append(prin) prin1 = '\n'.join(prinr) except: pass window = tk.Tk(className='请查看您曾经添加的考试信息') scrollbar = tk.Scrollbar(window) c = tk.Canvas(window, background="#42586E", yscrollcommand=scrollbar.set, width=770, height=800) scrollbar.config(command=c.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) c.pack(side="left", fill="both", expand=True) f = tk.Frame(c) c.create_window(0, 0, window=f, anchor='nw') new_pwd = tk.StringVar() l1 = tk.Entry(c, textvariable=new_pwd, font=('微软雅黑', 12)) l1.place(x=5, y=24, width=190, height=30) new_pwd1 = tk.StringVar() l2 = tk.Entry(c, textvariable=new_pwd1, font=('微软雅黑', 12)) l2.place(x=220, y=24, width=64, height=30) new_pwd2 = tk.StringVar() l3 = tk.Entry(c, textvariable=new_pwd2, font=('微软雅黑', 12)) l3.place(x=334, y=24, width=44, height=30) new_pwd3 = tk.StringVar() l4 = tk.Entry(c, textvariable=new_pwd3, font=('微软雅黑', 12)) l4.place(x=444, y=24, width=60, height=30) new_pwd4 = tk.StringVar() l5 = tk.Entry(c, textvariable=new_pwd4, font=('微软雅黑', 12)) l5.place(x=560, y=24, width=50, height=30) new_pwd5 = tk.StringVar() l6 = tk.Entry(c, textvariable=new_pwd5, font=('微软雅黑', 12)) l6.place(x=670, y=24, width=30, height=30) button_img_gif11 = tk.PhotoImage(file='返回1.png') button_img11 = tk.Button(c, image=button_img_gif11, text='带图按钮', height=40, width=40, command=back) button_img11.place(x=710, y=38) button_img_gif12 = tk.PhotoImage(file='修改.png') button_img12 = tk.Button(c, image=button_img_gif12, text='带图按钮', height=70, width=70, command=revise) button_img12.place(x=310, y=68) button_img_gif13 = tk.PhotoImage(file='删除.png') button_img13 = tk.Button(c, image=button_img_gif13, text='带图按钮', height=70, width=70, command=delete) button_img13.place(x=410, y=68) label = tk.Label(f, wraplength=840, text=prin1, font=('微软雅黑', 18), fg="#E3D4AF", bg='#42586E', anchor='w') label.bind("<MouseWheel>", processWheel) label.pack() window.update() c.config(scrollregion=c.bbox("all")) f.bind("<MouseWheel>", processWheel) c.bind("<MouseWheel>", processWheel) c.pack() window.mainloop() # 加载图片2 button_img_gif = tk.PhotoImage(file='添加考试信息1.png') button_img = tk.Button(canvas, image=button_img_gif, text='带图按钮', height=147, width=246,bd = 0,command=addtest) button_img.place(x=10, y=10) button_img_gif1 = tk.PhotoImage(file='修改考试信息1.png') button_img1 = tk.Button(canvas, image=button_img_gif1, text='带图按钮', height=147, width=246,bd = 0,command = modify) button_img1.place(x=270, y=10) button_img_gif2 = tk.PhotoImage(file='查看考试信息1.png') button_img2 = tk.Button(canvas, image=button_img_gif2, text='带图按钮', height=147, width=246,bd = 0,command = seescore) button_img2.place(x=530, y=10) button_img_gif3 = tk.PhotoImage(file='设置意向专业1.png') button_img3 = tk.Button(canvas, image=button_img_gif3, text='带图按钮', height=147, width=246,bd = 0,command = setmajor) button_img3.place(x=10, y=170) button_img_gif4 = tk.PhotoImage(file='设置学科倾向度1.png') button_img4 = tk.Button(canvas, image=button_img_gif4, text='带图按钮', height=147, width=246,bd = 0,command=addlove) button_img4.place(x=270, y=170) button_img_gif5 = tk.PhotoImage(file='开始六选三评测1.png') button_img5 = tk.Button(canvas, image=button_img_gif5, text='带图按钮', height=147, width=246,bd = 0,command = evaluation) button_img5.place(x=530, y=170) button_img_gif6 = tk.PhotoImage(file='查看使用说明2.png') button_img6 = tk.Button(canvas, image=button_img_gif6, text='带图按钮', height=77, width=536,bd = 0,command = inst) button_img6.place(x=132, y=330) canvas.pack() window.protocol('WM_DELETE_WINDOW', on_closing) # 程序 window.mainloop() if quit == 1:#退出主程序 break
木子哦2021.09.26
你好,感谢参与比赛,请添加下微信号:DFRobot2019,补充下报名信息!