I'm trying to create a label which automatically shows the result from an inputed variable. Basically I'm trying to combine these two programs :
from tkinter import *
root = Tk()
var = StringVar()
var.set('hello')
l = Label(root, textvariable = var)
l.pack()
t = Entry(root, textvariable = var)
t.pack()
root.mainloop() # the window is now displayed
this one (source : Update Tkinter Label from variable) automatically updates the label, however it can only update it to what was inputed by the user.
and this one :
from tkinter import *
myWindow = Tk()
def MyCalculateFunction():
pressure, temprature = float(box_pressure.get()), float(box_temprature.get())
result = pressure + temperature
label_result.config(text="%f + %f = %f" % (pressure, temprature, result))
box_pressure = Entry(myWindow)
box_pressure.pack()
box_temprature = Entry(myWindow)
box_temprature.pack()
button_calculate = Button(myWindow, text="Calcuate", command=MyCalculateFunction)
button_calculate.pack()
label_result = Label(myWindow)
label_result.pack()
the problem I have with this one it that if the user changes the pressure or temperature, the result doesn't automatically change. (source : How to get value from entry (Tkinter), use it in formula and print the result it in label)
How can I make it so that when a user changes any variable, Python automatically calculates the new result and changes the label on its own?