Make tkinter label refresh at set time intervals without input
Tkinter root windows have a method called after which can be used to schedule a function to be called after a given period of time. So call that function itself like (you will have to create a class first):
def update_label(self): self.label.configure(cpuTemp) self.root.after(1000, self.update_label)
This will then reload your label every second.
This may help you: Creating a Timer with tkinter
TKINTER
Refresh, Update, Rerender
This code works for any type of Tkinter widget update
#!/usr/bin/env python3import sysimport timefrom tkinter import *# Global variablesrunning = True# Button action updaterdef callback(): if button_1["state"] == "disabled": button_1["state"] = "normal" else: button_1["state"] = "disabled" root.after(4000, callback)# Window setuproot = Tk()root.title("Buttons")root.geometry("400x300")# Buttons setupbutton_1 = Button(root, text="Learn Python", command=callback)button_1.pack()# Kills window without _tkinter.TclErrordef kill(): global running running = False sys.exit()# Software loopwhile running: root.protocol("WM_DELETE_WINDOW", kill) root.update()
Python version used to created this software is: >=3.x