Как вставить в text переменную? Python Tkinter

ломаю голову, вот код(вопрос ниже):

from tkinter import *

window = Tk()
window.geometry('400x250')
window.title('Опрос')

result = 0

def cliced_right(): # надо бы подкрасить ответы в зеленый - готово
    coransw.configure(bg = 'green')
    global result
    result += 1
    notcoransw.configure(bg ='white')

def clicked_notright(): # а нужна ли мне эта функция? - да
    global result
    result +=0
    notcoransw.configure(bg = 'red')
    coransw.configure(bg ='white')

quest1 = Label(window, text = 'Угадаете кнопку?', font = ('Calibri, 14'))
quest1.grid(column = 1, row = 0)
coransw = Button(window, text = 'Эта?', font = ('Calibri, 14'), width = 0, command = cliced_right)
coransw.grid(column = 1, row = 1 )
notcoransw = Button(window, text = 'Или эта?', font = ('Calibri, 14'), command = clicked_notright)
notcoransw.grid(column = 2, row = 1 )

res = Label(window, text = 'Ваш результат: ',  font = ('Calibri, 14')) # и как запихать сюда result?
res.grid(column = 1, row =3)

window.mainloop()

конкретно интересует эта строка:

res = Label(window, text = 'Ваш результат:',  font = ('Calibri, 14'))

Как сделать так, чтобы переменная result выводилась на экран с лэйблом res?


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

Автор решения: DGDays
from tkinter import *

window = Tk()
window.geometry('400x250')
window.title('Опрос')

result = 0

def cliced_right(): 
    coransw.configure(bg = 'green')
    global result
    result += 1
    '''notcoransw.configure(bg ='white')'''
    res['text'] = 'Ваш результат: {}'.format(result)

def clicked_notright(): 
    global result
    result +=0
    '''notcoransw.configure(bg = 'red')'''
    coransw.configure(bg ='white')
    res['text'] = 'Ваш результат: {}'.format(result)

quest1 = Label(window, text = 'Угадаете кнопку?', font = ('Calibri, 14'))
quest1.grid(column = 1, row = 0)
coransw = Button(window, text = 'Эта?', font = ('Calibri, 14'), width = 0, command = cliced_right)
coransw.grid(column = 1, row = 1 )

res = Label(window, text = 'Ваш результат: {}'.format(result),  font = ('Calibri, 14')) # и как запихать сюда result?
res.grid(column = 1, row =3)

window.mainloop()
→ Ссылка