0

我正在尝试制作一个提示用户求解方程的程序。我希望它在每次尝试后重置值。我想我会把一个随机生成器放入一个函数中并传递值来显示它们。但它不工作....

from tkinter import *
from tkinter import ttk
from tkinter.font import families
from PIL import ImageTk, Image
import random

root = Tk()
root.geometry("610x500")
root.resizable(width=False, height=False)

def rand(): 
    global num1
    global num2
    num1 = random.randrange(2, 9)
    num2 = random.randrange(2, 9) 

bg = PhotoImage(file = "fon.png")
label1 = Label(root, image = bg)
label1.place(x = 0, y = 0)

label2 = Label( root, text = "Solve the equation") 
label2.pack(pady = 50)

label3 = Label(root, text = num1)
label3.place(x = 280, y = 140)

label4 = Label(root, text = num2)
label4.place(x = 310, y = 140)

label5 = Label(root, text = '*')
label5.place(x = 295, y = 140)


e = Entry(root, width=50)
e.pack(pady=50)
e.get()
num3 = num1 * num2

def eq():
    
    user = e.get()
    int_answer = int(user)
    
    if num3 == int_answer:
        label8 = Label(root, text = "correct")
        label8.place(x = 400, y = 140)
        rand()
    else:
        label8 = Label(root, text = "incorrect")
        label8.place(x = 400, y = 140)
        rand()
        
button1 = Button(text='Check your answer', command=eq)
button1.place(x = 250, y = 200)


root.mainloop()
4

0 回答 0