Сложение чисел из одного поля с результатом вывода в другое Tkinter

Помогите разобраться. Как c помощью программы Tkinter вывести окно, где будет запрос на ввод числа и после нажатия на кнопку "Добавить" число будет добавляться к введенным ранее. Тоесть в одном поле нужно вводить по числу (бесконечное количество раз), а в другом будет выводиться их сумма. Не понимаю как вывести сумму.

from tkinter import *
from tkinter import messagebox
import math
 
def calculation():
    num = int(a.get())
    num2 = int(b.get())
    num2 = num2 + num

root = Tk()
root.title("Додавання чисел")
root.geometry("400x150")

a = StringVar()
b = StringVar()
Label(root, text="Введіть число").place(x=20, y=20)
Entry(root, textvariable=a).place(x=115, y=10)
Label(root, text="Отримуємо").place(x=20, y=55)
Entry(root, textvariable=b).place(x=115, y=55)

but = Button(text="Додати", command=calculation).place(x=200, y=100)


root.mainloop()

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

Автор решения: GrAnd

Вызвать b.set(...) в нужных местах.

from tkinter import *
from tkinter import messagebox
import math
 
def calculation():
    num = int(a.get())
    num2 = int(b.get())
    num2 = num2 + num
    b.set(str(num2))

root = Tk()
root.title("Додавання чисел")
root.geometry("400x150")

a = StringVar()
b = StringVar()
b.set("0")
Label(root, text="Введіть число").place(x=20, y=20)
Entry(root, textvariable=a).place(x=115, y=10)
Label(root, text="Отримуємо").place(x=20, y=55)
Entry(root, textvariable=b).place(x=115, y=55)

but = Button(text="Додати", command=calculation).place(x=200, y=100)

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