




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于python-tkinter的答题系统答题系统的设计⾸先我们需要⼀个题库,这个题库可以采⽤数据库,也可以使⽤execl,这⾥我们由于execl笔记⽅便的。所以我们使⽤execl,execl的设计。使⽤的⼯具python第三⽅库pandas读取execl题库pillow加载背景照⽚内置库random实现随机抽题thinker实现布局问题界⾯设计提⽰信息:根据答对与否,提⽰相应的信息。‘下⼀题:仅在答完题后显⽰,下⼀题代码设计界⾯设计类classApp:def__init__(self,win):self.win=win#设置窗⼝⼤⼩self.width=900self.height=600#获取屏幕尺⼨以计算布局参数,使窗⼝居屏幕中央self.screenwidth=win.winfo_screenwidth()self.screenheight=win.winfo_screenheight()alignstr='%dx%d+%d+%d'%(self.width,self.height,(self.screenwidth-self.width)/2,(self.screenheight-self.height)/2)self.win.geometry(alignstr)#⼤⼩不可变,更改为True则可变self.win.resizable(width=False,height=False)#设置标题self.win.title('答题系统')self.img=tk.PhotoImage(file='./LittleProgram/AnswerSquare.gif')#获取数据self.data=r.get()self.text_topic=tk.StringVar()self.text_topic.set(self.data['题⽬'])self.text_A=tk.StringVar()self.text_A.set(self.data['A'])self.text_B=tk.StringVar()self.text_B.set(self.data['B'])#点击下⼀题后进⾏的逻辑操作#点击下⼀题后进⾏的逻辑操作defbegin(self):print('*'*50)print('下⼀题:1111')self.data=r.get()#self.text_topic=tk.StringVar()self.text_topic.set(self.data['题⽬'])#self.text_A=tk.StringVar()self.text_A.set(self.data['A'])#self.text_B=tk.StringVar()self.text_B.set(self.data['B'])self.canvas.delete(self.hint)self.canvas.delete(self.next)b1=tk.Button(self.win,textvariable=self.text_A,font=("宋体",20),image=self.img,bd=1,width=20,height=50,compound="center",wraplength=200,fg='#FFF',command=self.verify_A)b1.pack()self.cb1=self.canvas.create_window(200,350,width=200,height=100,window=b1)b2=tk.Button(self.win,textvariable=self.text_B,font=("宋体",20),image=self.img,bd=1,width=20,height=50,compound="center",wraplength=200,fg='#FFF',command=self.verify_B)b2.pack()self.cb2=self.canvas.create_window(700,350,width=200,height=100,window=b2)defrun(self):self.canvas=tk.Canvas(self.win,width=1100,height=600,bd=0,highlightthickness=0)imgpath='./LittleProgram/bg96.gif'img=Image.open(imgpath)photo=ImageTk.PhotoImage(img)self.canvas.create_image(self.width/2,self.height/2,image=photo)self.canvas.pack()topic=Label(self.win,textvariable=self.text_topic,font=("华⽂⾏楷",20),wraplength=500,width=500,height=120,anchor="w",justify=tk.CENTER)topic.pack()self.canvas.create_window(450,100,width=500,height=120,window=topic)photo2=tk.PhotoImage(file='./LittleProgram/AnswerSquare.gif')b1=tk.Button(self.win,textvariable=self.text_A,font=("宋体",20),image=photo2,bd=1,width=20,height=50,compound="center",wraplength=200,fg='#FFF',command=self.verify_A)b1.pack()self.cb1=self.canvas.create_window(200,350,width=200,height=100,window=b1)b2=tk.Button(self.win,textvariable=self.text_B,font=("宋体",20),image=photo2,bd=1,width=20,height=50,compound="center",wraplength=200,fg='#FFF',command=self.verify_B)b2.pack()self.cb2=self.canvas.create_window(700,350,width=200,height=100,window=b2)self.win.mainloop()defverify_create(self):self.canvas.delete(self.cb1)self.canvas.delete(self.cb2)#photo3=tk.PhotoImage(file='./LittleProgram/AnswerSquare.gif')b3=tk.Button(self.win,text='下⼀题',font=("宋体",20),bd=2,width=20,height=50,compound="center",command=self.begin)self.next=self.canvas.create_window(450,400,width=200,height=100,window=b3)defverify_A(self):print('你的A')ifself.data['T']=='A':print('恭喜你答对了。')self.hint=self.canvas.create_text(435,230,#使⽤create_text⽅法在坐标(302,77)处绘制⽂字text='恭喜你,答对了!'#所绘制⽂字的内容,fill='green',font=("微软雅⿊",25))self.canvas.delete(self.cb1)self.canvas.delete(self.cb2)#photo3=tk.PhotoImage(file='./LittleProgram/AnswerSquare.gif')b3=tk.Button(self.win,text='下⼀题',font=("宋体",20),bd=2,width=20,height=50,compound="center",command=self.begin)self.next=self.canvas.create_window(450,400,width=200,height=100,window=b3)else:print('打错了')self.hint=self.canvas.create_text(435,230,#使⽤create_text⽅法在坐标(302,77)处绘制⽂字text='你回答错了!'#所绘制⽂字的内容,fill='red',font=("微软雅⿊",25))self.verify_create()defverify_B(self):print('你的B')ifself.data['T']=='B':print('恭喜你答对了。')self.hint=self.canvas.create_text(435,230,#使⽤create_text⽅法在坐标(302,77)处绘制⽂字text='恭喜你,答对了!'#所绘制⽂字的内容,fill='green',font=("微软雅⿊",25))self.verify_create()else:print('打错了')self.hint=self.canvas.create_text(435,230,#使⽤create_text⽅法在坐标(302,77)处绘制⽂字text='你回答错了!'#所绘制⽂字的内容,fill='red',font=("微软雅⿊",25))self.verify_create()数据获取类*classRead_excel:def__init__(self):self.data={}self.df=pd.read_excel('./LittleProgram/题库.xlsx',sheet_name=0)defget(self):globalflagifflag==4:flag=0self.df=pd.read_excel('./LittleProgram/题库.xlsx',sheet_name=flag)index=random.randint(0,len(self.df['题⽬编号'])-1)print(self.df.iloc[index])self.data['题⽬']=str(fl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 告别北上广创业在家乡
- 2024年特许金融分析师考前冲刺试题及答案
- 辽宁省沈阳市浑南区广全实验学校2024-2025学年高一下学期第一次月考地理试卷(解析版)
- 童真趣味美术课件
- 2024年特许金融分析师考试备考技巧试题及答案
- 2025年贵州省黔南州高考历史二模试卷
- 2025届甘肃省兰州市高三下学期诊断考试(一模)历史试题
- 高中政治精美课件
- 学生创业意识的要素
- 2024年CFA模拟考试指南试题及答案
- 中国保险行业协会官方-2023年度商业健康保险经营数据分析报告-2024年3月
- 《公共管理学》重点总结-陈振明版
- QBT 3653-1999 羽毛球拍行业标准
- 犬的品种-犬的品种类型及外貌鉴定
- 可信工业数据空间系统架构1.0
- 人教版数学小学六年级下册第一单元测试卷含答案(共10套)
- 工地防火技术方案
- (2024年)团的发展史
- 《审计实务》第4讲 函证程序(上)
- IMDS相关培训资料
- 心源性晕厥的护理
评论
0/150
提交评论