写在前面
加入了方程题目。
(灵感来源:作业上的方程题😅)
源码
import random
from tkinter import *
#计算题
def calculate(min_val1, max_val1, min_val2, max_val2):
num1 = round(random.uniform(min_val1, max_val1), 2)
num2 = round(random.uniform(min_val2, max_val2), 2)
num3 = num1
num4 = round(100 - num2, 2)
expr = str(num1)+'×'+str(num2)+'+'+str(num3)+'×'+str(num4)
return expr
#方程
def equation():
a = random.randint(-10, 10)
if a == 0:
a = random.randint(1, 10)
b = random.randint(-10, 10)
sign_a = '-' if a < 0 else ''
sign_b = '-' if b < 0 else '+'
if b == 0:
equation = f"{sign_a}{abs(a)}x = 0"
else:
equation = f"{sign_a}{abs(a)}x {sign_b} {abs(b)} = 0"
return equation
def topic():
global A_e, B_e, C_e, D_g, E_g,X_a, Y_a;
A_e = calculate(10, 100, 10, 100)
B_e = calculate(10, 100, 10, 100)
C_e = calculate(10, 100, 10, 100)
D_g = calculate(10, 100, 10, 130)
E_g = calculate(10, 100, 10, 130)
X_a = equation()
Y_a = equation()
def up_date():
date = topic()
label1.config(text = A_e, font = ("微软雅黑", 15))
label2.config(text = B_e, font = ("微软雅黑", 15))
label3.config(text = C_e, font = ("微软雅黑", 15))
label4.config(text = D_g, font = ("微软雅黑", 15))
label5.config(text = E_g, font = ("微软雅黑", 15))
label6.config(text = X_a, font = ("微软雅黑", 15))
label7.config(text = Y_a, font = ("微软雅黑", 15))
def butt():
label.destroy()
button.destroy()
button1 = Button(root, text='重新生成', width = 20, height = 1, command = butt)
button1.place(x = 0, y = 0)
timer = root.after(0, up_date)
root = Tk()
root.title(" 题目生成器 V4.1")
root.geometry("500x500+100+100")
date = topic()
label1 = Label(root, text=' ', font = ("微软雅黑", 15))
label1.place(x = 0, y = 30)
label2 = Label(root, text=' ', font = ("微软雅黑", 15))
label2.place(x = 0, y = 60)
label3 = Label(root, text=' ', font = ("微软雅黑", 15))
label3.place(x = 0, y = 90)
label4 = Label(root, text=' ', font = ("微软雅黑", 15))
label4.place(x = 0, y = 120)
label5 = Label(root, text=' ', font = ("微软雅黑", 15))
label5.place(x = 0, y = 150)
label6 = Label(root, text=' ', font = ("微软雅黑", 15))
label6.place(x = 0, y = 210)
label7 = Label(root, text=' ', font = ("微软雅黑", 15))
label7.place(x = 0, y = 240)
label = Label(root, text='欢迎使用题目生成器!', font = ('微软雅黑', 20))
button = Button(root, text='生成题目', font = ('微软雅黑', 15), command = butt)
label.place(x = 120, y = 150)
button.place(x = 190, y = 200)
root.mainloop()
效果图
(开始界面▲)
(主界面▲)
注意⚠️
方程有一些题是-x。