I am creating a interface so that I can see temperature, pressure and humidity on a gui on a raspberry pi 7" touchscreen. However I am having trouble with updating the temperature (I haven't done humidity or pressure yet), so what happens is when I run the program it does display the temperature when it is run but it does not continuously update it.
Here is my code, not all of the application however the part at which the tempreture is read and displayed.
main_window = Tk()
temp = sense.get_temperature()
tempreture_label = Label(main_window, text = temp)
tempreture_label.pack()
main_window.mainloop()
I have been looking at other questions where they recommend using set() in slightly similar situations but I cant work out how it would help me.
I have also tried linking my problem to a updating tkinter clock however I believe I am confusing myself.
Any help wold be greatful
You can use
aftermethod to periodically update the label's text assumingsense.get_temperature()returns the temperature when called:Based on Bryan's suggestion which makes use of
after's*args,temperature_label.after(period_ms, lambda arg = period_ms: temp_up(arg))line is replaced with the suggested line.