准备
好久没有更新了,这一次我们来制作数学口算练习器,先win+r输入cmd,pip install PySimpleGUI,这样,图形化模块就安装好了,接下来我们来制作数学口算练习器。
制作
先引入模块PySimpleGUI(图形化模块)和random(随机数模块):
然后进行程序初始化
while 1==1:
lsls=0
tctc=0
if 1==1:
#------------图形化界面设计——————————————————
layout=[
[sg.Text("欢迎来到数学闯关小游戏",relief='ridge',border_width=5,font=('华文彩云',15))],
[sg.Button('初级'),sg.Button('中级'),sg.Button('高级'),sg.B("帮助"),sg.B("退出")]
]
window=sg.Window('数学闯关',layout)
#------------图形化界面设计结束——————————————————
#出题初始化
while True:
event,values=window.read()
if event==None:
tctc=1
break
if event=='初级':
jia1=20
jian1=20
jia2=20
jian2=20
sjsj=2
break
if event=='中级':
jia1=100
jian1=100
jia2=100
jian2=100
chen1=10
chen2=10
sjsj=3
break
if event=="高级":
jia1=1000
jian1=1000
jia2=1000
jian2=1000
chen1=100
chen2=10
chu1=100
chu2=10
sjsj=4
break
if event=="退出":
tctc=1
break
if event=="帮助":
sg.popup("数学闯关小游戏;\n初级为20以内的加减法;\n中级为100以内的加减及10以内乘法;\n高级为100以内加减及100*10以内的乘除法。",title="数学闯关")
window.close()
if tctc==1:
break
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
出题:
#接在while True下面
if lsls==0:
dui=0
zong=0
qqq=0
while 1==1:
a=random.randint(1,sjsj)
if a==1:
b=random.randint(0,jia1)
c=random.randint(0,jia2)
d=str(b)+"+"+str(c)+"="
e=b+c
elif a==2:
b=random.randint(0,jian1)
c=random.randint(0,jian2)
if b-c<0:
while b-c<0:
b=random.randint(0,jian1)
c=random.randint(0,jian2)
d=str(b)+"-"+str(c)+"="
e=b-c
elif a==3:
b=random.randint(0,chen1)
c=random.randint(0,chen2)
d=str(b)+"X"+str(c)+"="
e=b*c
elif a==4:
e=random.randint(0,chu1)
c=random.randint(1,chu2)
b=e*c
d=str(b)+"/"+str(c)+"="
zong+=1
layout=[
[sg.T(" "),sg.Text("欢迎来到数学闯关小游戏",relief='ridge',border_width=5,font=('华文彩云',15))],
[sg.Text(d),sg.InputText(key="-Q-")],
[sg.Button('提交',bind_return_key=True),sg.Button('跳过'),sg.Button('退出')]
]
window=sg.Window('数学闯关',layout)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
判断对错
while True:
event,values=window.read()
if event==None:
window.close()
sg.popup("答题报告)答对题数:"+str(dui)+"总题数"+str(zong))
qqq=1
break
if event=='提交':
if values["-Q-"]==str(e):
sg.popup("恭喜你,答对了! ok进入下一关~")
dui+=1
break
else:
sg.popup("很遗憾,答错了! ok进入重来~~")
if event=='退出':
window.close()
sg.popup("答题报告)答对题数:"+str(dui)+",总题数:"+str(zong)+",百分比:"+str(dui/zong*100)+"%",title="答题报告")
qqq=1
break
if event=="跳过":
break
if qqq==1:
break
window.close()
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
写在最后
好了,本片文章就到这里了,如果图形化不太懂的可以参照我以前的文章,再见。