0

Создаю программу, которая генерирует рандомный пример, при этом если на него ответили правильно, то программа генерирует новый. При нажатии на кнопку возникает ошибка AttributeError: 'NoneType' object has no attribute 'grid_forget'

from tkinter import *
import time
import random as r


root = Tk()
root.title('Tkinter')
root.geometry('200x200')

num1 = str(r.randint(1, 24))
num2 = str(r.randint(0, 24))

score = 0

a = str(num1) + ' * ' + str(num2)
b = Label(root, text=score)
c = int(num1) * int(num2)



def question():
    global answer
    global math
    label = Label(root, text='Решите пример:').grid(row=0, column=0)
    math = Label(root, text=a).grid(row=0, column=1)

    btn = Button(root, text='Проверить')
    btn.bind('<Button-1>', answer_check)
    btn.grid(row=3)

    answer = Entry(root)
    answer.grid(row=2)



def answer_check(event):
    answer_string = answer.get()                                                 
    answer_int = int(answer_string)
    global score
    if answer_int == c:
        score += 1
        Label(root, text='True').grid(row=4)
        Label(root, text='Ваш счет: ' + str(score)).grid(row=5)
        math.grid_forget()
        question()
    else:
        Label(root, text='Не правильно! Игра окончена.' + 'Ваш результат: ' + str(score) + '    
очков!').grid(row=4)




question()

root.resizable(False, False)
root.mainloop()

1 ответ 1

1
def question():
    global answer
    global math
    label = Label(root, text='Решите пример:').grid(row=0, column=0)
    math = Label(root, text=a)
    math.grid(row=0, column=1)

    btn = Button(root, text='Проверить')
    btn.bind('<Button-1>', answer_check)
    btn.grid(row=3)

    answer = Entry(root)
    answer.grid(row=2)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.