-
Notifications
You must be signed in to change notification settings - Fork 0
/
wangsu.py
37 lines (32 loc) · 853 Bytes
/
wangsu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import psutil
import time
from tkinter import *
def make_app():
app = Tk()
app.geometry('300x150')
app.config(bg='#303030')
Label(text='Speed Monitor',
font=('Arial',25,'bold'),
bg='#303030',
fg='white').pack()
Label(name='lb2',
text='_kb/s',
font=('Hack',20,'bold'),
bg='#303030',
fg='white'
).pack()
return app
def speed_test():
s1 = psutil.net_io_counters(pernic=True)['en0']
time.sleep(1)
s2 = psutil.net_io_counters(pernic=True)['en0']
result = s2.bytes_recv - s1.bytes_recv
return str(result/1024) + 'kb/s'
def ui_update(do):
data = do()
lb2 = app.children['lb2']
lb2.config(text=data)
app.after(1000,lambda:ui_update(do))
app = make_app()
app.after(1000, lambda:ui_update(speed_test))
app.mainloop()