Как сделать проверку ответа, выбираемого кнопками?

Помогите сделать проверку ответа. Ответ выбирается кнопками.
Мой код:

from tkinter import *


def check():



def start():
    Bs.place_forget()
    Lt['text'] = '1. Что стоит перед суфиксом и после приставки?'
    B1['text'] = ' Корень* '
    B2['text'] = 'Приставка'
    B3['text'] = 'Окончание'
    B4['text'] = '   144   '
    B1.place(x=120, y=180)
    B2.place(x=610, y=180)
    B3.place(x=120, y=360)
    B4.place(x=610, y=360)


def qs2():
    Bs.place_forget()
    Lt['text'] = '2. Сколько будет 2*8-3+5-2'
    B1['text'] = ' 65 '
    B2['text'] = '23'
    B3['text'] = '12'
    B4['text'] = '   16*   '
    B1.place(x=120, y=180)
    B2.place(x=610, y=180)
    B3.place(x=120, y=360)
    B4.place(x=610, y=360)


def call_func():
    start()
    qs2()


win = Tk()
win.title('имя')
win.geometry('1080x720')
# win.state('zoomed')


Lt = Label(win, text='Здравствуйте\nНажмите на кнопку ниже', font='Arial 30 bold', fg='white')
Lt.place(x=540, y=90, anchor=CENTER)
Bs = Button(win,
            command=start,
            text='Начало',
            font='Arial 40 bold',
            fg='white'
            )
Bs.place(x=540, y=360, anchor=CENTER)
B1 = Button(win,
            command=call_func,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B2 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B3 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B4 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )


mainloop()

Ответы (1 шт):

Автор решения: Konstantin Penkov

Вам нужно сделать две функции - для обработки соответственно правильного и неправильного ответов. Пусть они будут называться correct_ans и wrong_ans.

По сути здесь проверять ничего не нужно, так как известно, какая кнопка содержит правильный вариант ответа. Нужно в функции запусков заданий (start и qs2) для кнопки с правильным ответом устанавливать поле command в correct_ans, а для остальных кнопок - wrong_ans.

В этих функциях пропишите обработку правильного/неправильного ответа пользователя.

пример реализации:

from tkinter import *


def correct_ans():
    print('правильно')
    qs2()
def wrong_ans():
    print('неправильно')
    qs2()


def start():
    Bs.place_forget()
    Lt['text'] = '1. Что стоит перед суфиксом и после приставки?'
    B1['text'] = ' Корень* '
    B2['text'] = 'Приставка'
    B3['text'] = 'Окончание'
    B4['text'] = '   144   '
    B1['command'] = correct_ans
    B2['command'] = wrong_ans
    B3['command'] = wrong_ans
    B4['command'] = wrong_ans
    B1.place(x=120, y=180)
    B2.place(x=610, y=180)
    B3.place(x=120, y=360)
    B4.place(x=610, y=360)


def qs2():
    Bs.place_forget()
    Lt['text'] = '2. Сколько будет 2*8-3+5-2'
    B1['text'] = ' 65 '
    B2['text'] = '23'
    B3['text'] = '12'
    B4['text'] = '   16*   '
    B1['command'] = wrong_ans
    B2['command'] = wrong_ans
    B3['command'] = wrong_ans
    B4['command'] = correct_ans
    B1.place(x=120, y=180)
    B2.place(x=610, y=180)
    B3.place(x=120, y=360)
    B4.place(x=610, y=360)


def call_func():
    #start()
    qs2()


win = Tk()
win.title('имя')
win.geometry('1080x720')
# win.state('zoomed')


Lt = Label(win, text='Здравствуйте\nНажмите на кнопку ниже', font='Arial 30 bold', fg='white')
Lt.place(x=540, y=90, anchor=CENTER)
Bs = Button(win,
            command=start,
            text='Начало',
            font='Arial 40 bold',
            fg='white'
            )
Bs.place(x=540, y=360, anchor=CENTER)
B1 = Button(win,
            command=call_func,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B2 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B3 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )
B4 = Button(win,
            # command=,
            text='',
            font='Arial 40 bold',
            fg='white'
            )


mainloop()
→ Ссылка