您当前的位置: 首页 >  Python

嗨学编程

暂无认证

  • 0浏览

    0关注

    1405博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

程序员的自我救赎,使用python开发性格分析工具

嗨学编程 发布时间:2019-11-15 15:39:07 ,浏览量:0

前言

文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。

作者: 王翔

PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取

python免费学习资料以及群交流解答点击即可加入

九型人格

在这里插入图片描述

今天,我们就用Python开发一套九型人格性格分析工具。用以让更多的人,了解自己的性格分类!

既然是九型人格分析,首先我们需要拿到它的测试题。翻了很久,知道了百度文库的测试原题:

在这里插入图片描述 测试题总共36道,通过各场景下的行为表现,最终分析出你最接近的人格分类。现在题有了,如何做出测试题呢?我选择使用Python的tkinter模块,将测试题开发为一个可执行的exe工具,说干就干!

基础准备

为了能将代码打包成单独的可执行文件,我们需要先准备测试题与对应的答案,然后提前存储在代码中。我们需要进行相关拆分,这种苦力活就交给拥有雷锋精神的我来完成吧: 在这里插入图片描述

界面开发

界面无需太过复杂,提供说明、题目、选项作答、题目切换与操作按钮即可。当然,交卷后,需要显示用户的测试结果,那么开始吧!

30 minutes later…完成!

Main.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('九型人格测试 | 公众号: 清风Python')
ExamPage(root)
root.mainloop()

Enneagram_GUI.py


 # coding:utf-8
 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             
关注
打赏
1663681728
查看更多评论
0.0533s