I have just started learning Python and I couldn't figure this one out, Basically I want to monitor my network traffic, and running this code below will only show the results which were captured at the moment but it doesn't update
from tkinter import*
import psutil,os
from psutil._common import bytes2human
from threading import Timer
import time
netmon = Tk()
netmon.title("NetMonitor")
netmon.geometry("200x80")
def getresults():
total_before = psutil.net_io_counters()
time.sleep(1)
total_after = psutil.net_io_counters()
download_rate = "Download : " + bytes2human(total_after.bytes_recv - total_before.bytes_recv) + " KB/S"
upload_rate = "Upload : " + bytes2human(total_after.bytes_sent - total_before.bytes_sent) + " KB/S"
text = Label(netmon, text = "\n" + download_rate + "\n\n" + upload_rate, anchor = NW)
text.pack()
#Timer(5, getresults).start
getresults()
netmon.mainloop()
I have tried with while loop :
.
.
.
while True:
getresults()
netmon.mainloop()
and I have tried the Timer from Threading but in both cases the "program" wont even launch till I revert to the first code I mentioned above, can anyone tell me how to make it update every second for example?