import openpyxl
import random
import tkinter as tk
from tkinter.filedialog import askdirectory
main = tk.Tk()
main.title ("随机出数学题")
group = tk.LabelFrame (main ,text ='选择出题类型',padx =5 ,pady =5)
group.grid(row=1,column=0)
vv= tk.IntVar()
r1 = tk.Radiobutton(group, text="加减法", variable=vv, value=1).grid(row=2,column=0)
r2 = tk.Radiobutton(group, text="乘法", variable=vv, value=2).grid(row=2,column=1)
r3 = tk.Radiobutton(group, text="整除法", variable=vv, value=3).grid(row=2,column=2)
v1 = tk.StringVar()
g2 = tk.LabelFrame (main ,text ='选择最小值' ,padx =5 ,pady =5)
g2.grid(row=3,column=0)
e1 = tk.Entry(g2,textvariable=v1).grid(row=3,column=1)
v2 = tk.StringVar()
g3 = tk.LabelFrame (main ,text ='选择最大值' ,padx =5 ,pady =5)
g3.grid(row=4,column=0)
e2 = tk.Entry(g3,textvariable=v2).grid(row=4,column=1)
lista = [] #存储题目
listb =[] #存储答案
listll =[] #存储题目
liste= [] #存储entry名字
ans = [] #存储entry结果
ansf=[]
listl =[] #存储结果label名字
fed= [] #存储结果对应标签的textvariable值
def fun():
main1 = tk.Toplevel() #生产新的界面
sb = tk.Scrollbar(main1)
main1.title('随机数学题')
s =int(v1.get())
a =int( v2.get())
qty =1
for i in range (0,50):
ans1 ='a'+str(i)
ee = "e" + str(i)
ll = "l" + str(i)
lll = "ll"+str(i)
fed1 ='fed'+str(i)
liste.append(ee)
listl.append(ll)
listll.append(lll)
ans.append(ans1)
fed.append(fed1)
print (ans)
if vv.get() == 1 : #50道随机加减法
while qty <=50:
qty+=1
c=int(random.randint(s,a))
f=int(random.randint(s,a))
jz=random.randint(0,1)
if jz>=0.5:
test = ("%d. %d+%d = "%(qty-1,c,f))
res = c+f
else:
if c>= f:
test = ("%d. %d-%d = "%(qty-1,c,f))
res =c-f
else:
test = ("%d. %d-%d = "%(qty-1,f,c))
res = f-c
lista.append(test)
listb.append(res)
com3= tk.Button(main1,text = '提交结果',command = check)
com3.grid(row = 0,column = 2)
for qq in range (0,50):
ans[qq] =tk.StringVar()
listll[qq] = tk.LabelFrame(main1, text = lista[qq],font=("微软雅黑", 13))
listll[qq].grid(row = qq//5+1,column= qq%5)
liste[qq] = tk.Entry (listll[qq],textvariable= ans[qq]).pack()
main1.mainloop()
def check():
fb=[]
for aas in range (0,50):
ans11 =ans[aas].get()
if ans11 == '':
ans11 = 0
print(ans11)
if int(ans11) ==int(listb[aas]):
fed[aas]='正确'
else:
fed[aas]='错误'
listl[aas] = tk.Label(listll[aas],text=fed[aas]).pack()
print (fed)
com2 =tk.Button( main ,text ='出题',width=10,command =fun)
com2.grid (row =0 ,column =0)
main.mainloop()