#mian.py
from Enneagram_GUI import *
from tkinter import *
def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(size)
root = Tk()
center_window(root, 750, 700)
root.resizable(width=False, height=False)
root.title('人格测试 | 微信小程序:璇月')
ExamPage(root)
root.mainloop()
#key function
from tkinter import *
import Enneagram_Exam
import Enneagram_Result
import tkinter.messagebox
# 自测说明
Standard = '此份问卷共有36道测试题目,请在每题中选择你认为最恰当或者最接近描述自己的性格行为的句子,\n' \
'请全部作答,最高分的项目很可能成为你的基本性格型态。'
# 人格类型矩阵
Style_Dict = [
{3: 2, 6: 2, 10: 2, 15: 2, 19: 1, 22: 2, 28: 2, 32: 2},
{1: 1, 6: 1, 12: 1, 17: 2, 20: 1, 23: 1, 29: 1, 33: 1},
{4: 1, 7: 1, 10: 1, 14: 2, 23: 2, 26: 2, 30: 1, 34: 1},
{2: 1, 8: 2, 12: 2, 16: 1, 21: 2, 24: 1, 28: 1, 34: 2},
{1: 2, 4: 2, 13: 1, 16: 2, 19: 2, 25: 1, 31: 1, 36: 1},
{5: 1, 9: 2, 14: 1, 18: 1, 21: 1, 25: 2, 29: 2, 32: 1},
{2: 2, 7: 2, 11: 2, 18: 2, 22: 1, 27: 2, 33: 2, 36: 2},
{3: 1, 9: 1, 13: 2, 17: 1, 24: 2, 27: 1, 20: 2, 35: 2}
]
class ExamPage:
def __init__(self, master=None):
self.root = master
# 用户结果集
self.user_result = {}
self.status = 1
self.All_Exam = Enneagram_Exam
self.normal_choice = IntVar()
self.start_exam()
# 上一题方法
def before(self):
if self.normal_choice.get() != 0:
self.user_result[self.status] = self.normal_choice.get()
if self.status > 1:
self.status -= 1
self.body.grid_forget()
self.main_exam()
else:
tkinter.messagebox.showwarning("提示:", message="请先选择答案!")
# 下一题方法
def after(self):
if self.normal_choice.get() != 0:
self.user_result[self.status] = self.normal_choice.get()
if self.status < len(Enneagram_Exam.Exam):
self.status += 1
self.body.grid_forget()
self.main_exam()
else:
tkinter.messagebox.showwarning("提示:", message="请先选择答案!")
# 获取当前题目
def exam_files(self, num):
return list(map(lambda x: x.split('.'), self.All_Exam.Exam[num - 1].strip().split('\n')))
# 交卷
def hand_paper(self):
self.user_result[self.status] = self.normal_choice.get()
if len(self.user_result) != 36:
tkinter.messagebox.showwarning("提示:", message="您还有未完成的测试题!")
else:
self.exam_result = LabelFrame(self.root, text="测试结果", padx=10, pady=10, fg="red", font=("黑体", '11'))
self.exam_result.grid(padx=10, pady=5, sticky=NSEW)
sc = Scrollbar(self.exam_result)
sc.grid(row=0, column=1, sticky=NS)
result_info = Text(self.exam_result, font=("黑体", '11'), width=85, yscrollcommand=sc.set)
result_info.grid(row=0, column=0, sticky=NSEW)
sc.config(command=result_info.yview)
all_num = []
for style in Style_Dict:
calc_num = list(
point for point in self.user_result if point in style and self.user_result[point] == style[point])
if calc_num == None:
all_num.append(0)
else:
all_num.append(len(calc_num))
user_type = all_num.index(max(all_num))
for line in Enneagram_Result.Result[user_type]:
result_info.insert(END, line)
# 启动测试所需控制按钮
def start_exam(self):
self.title =