|
楼主 |
发表于 2021-2-4 14:46:11
|
显示全部楼层
存excel的已经写好了 ,想搞个直接算的小程序
# TK界面随机产生数学题
import openpyxl
wb= openpyxl.Workbook()
ws=wb.active
import random
import tkinter as tk
from tkinter.filedialog import askdirectory
from openpyxl.styles import Font, Border
def fun():
s =int(v1.get())
a =int( v2.get())
b = int(v3.get())
route = path.get()
ws.column_dimensions['A'].width = 30
ws.column_dimensions['B'].width = 30
ws.column_dimensions['C'].width = 30
ws.column_dimensions['D'].width = 30
qty =1
if vv.get() == 1 :
for i in range (1,int(b/4)+3):
ws.row_dimensions[i].height = 30
for j in range (1,5):
kk = ws.cell(row=i,column=j)
fonta = Font(name ='Arial',size = 16 )
kk.font = fonta
if qty< b+1:
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))
kk.value=test
else:
if c>= f:
test1 = ("%d. %d-%d = "%(qty-1,c,f))
kk.value=test1
else:
test1 = ("%d. %d-%d = "%(qty-1,f,c))
kk.value=test1
else:
kk.value=""
wb.save(r'%s\加减法%d-%d %道.xlsx'% (route,s,a,b))
if vv.get()==2 :
for i in range (1,int(b/4)+3):
ws.row_dimensions[i].height = 30
for j in range (1,5):
kk = ws.cell(row=i,column=j)
fonta = Font(name ='Arial',size = 16 )
kk.font = fonta
if qty < b+1:
qty+=1
c=int(random.randint(s,a))
f=int(random.randint(s,a))
test =("%d. %d × %d = "%(qty-1,c,f))
kk.value=test
else:
kk.value=""
wb.save(r'%s\乘法%d-%d %d道.xlsx'% (route,s,a,b))
if vv.get() == 3:
for i in range (1,int(b/4)+3):
ws.row_dimensions[i].height = 30
for j in range (1,5):
kk = ws.cell(row=i,column=j)
fonta = Font(name ='Arial',size = 16 )
kk.font = fonta
if qty < b+1:
qty+=1
c=int(random.randint(s,a))
d = int (random.randint(1,int(a/2)))
qq= c//d
aas = c % d
if qq >2 :
test = ("%d. %d ÷%d = "%(qty-1, c-aas+d ,d))
else :
if c-aas+2*d < a:
test = ("%d. %d ÷%d = "%(qty-1, c-aas+2*d ,d))
else:
test = ("%d. %d ÷%d = "%(qty-1, c//(d-1)*(d-1) ,d-1))
kk.value =test
else:
kk.value = ""
wb.save(r'%s\整除法%d-%d %d道.xlsx'% (route,s,a,b))
main = tk.Tk()
main.title ("随机出数学题")
main.geometry("600x500")
def routing():
path_ = askdirectory()
path.set(path_)
group = tk.LabelFrame (main ,text ='选择出题类型',padx =5 ,pady =5)
group.pack(padx =20 ,pady =20)
vv= tk.IntVar()
r1 = tk.Radiobutton(group, text="加减法", variable=vv, value=1).pack(anchor="w")
r2 = tk.Radiobutton(group, text="乘法", variable=vv, value=2).pack(anchor="w")
r3 = tk.Radiobutton(group, text="整除法", variable=vv, value=3).pack(anchor="w")
path = tk.StringVar()
v1 = tk.StringVar()
g2 = tk.LabelFrame (main ,text ='选择最小值' ,padx =5 ,pady =5)
g2.pack(padx =10 ,pady =10)
e1 = tk.Entry(g2,textvariable=v1).pack(anchor="w")
v2 = tk.StringVar()
g3 = tk.LabelFrame (main ,text ='选择最大值' ,padx =5 ,pady =5)
g3.pack(padx =10 ,pady =10)
e2 = tk.Entry(g3,textvariable=v2).pack(anchor="e")
v3 = tk.StringVar()
g4 =tk.LabelFrame (main ,text ='出题数量' ,padx =5 ,pady =5)
g4.pack(padx =10 ,pady =10)
e3 = tk.Entry(g4,textvariable=v3).pack(anchor="w")
g5 =tk.LabelFrame (main ,text ='保存路径' ,padx =5 ,pady =5)
g5.pack(padx =10 ,pady =10)
e4 = tk.Entry(g5,textvariable = path).pack(anchor="w")
com1 =tk.Button( g5 ,text ='路径选择',command = routing)
com1.pack()
com2 =tk.Button( main ,text ='出题',width=10,command = fun)
com2.pack()
main.mainloop()
|
|