• 大小: 2.44KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2024-05-08
  • 语言: Python
  • 标签: 实时  显示  

资源简介

显示实时网速(上传和下载速度),运用简单算法,显示实时网速。优点是代码短

资源截图

代码片段和文件信息

from tkinter import *
import time
import psutil
import threading

def main():
    traffic_io=psutil.net_io_counters()[:2]
    while True:
        time.sleep(0.5)
        traffic_ioNew=psutil.net_io_counters()[:2]
        diff=(traffic_ioNew[0]-traffic_io[0]traffic_ioNew[1]-traffic_io[1])
        traffic_io=traffic_ioNew
        diff=tuple(map(lambda x:x*2/1024diff))
        
        if diff[1]>3840:
            p=“\n可能有文件正在下载中!“
        else:
            p=‘当前网络处于空闲状态‘
        if diff[0]==0 and diff[1]==0:
            k=0
            for i in range(2):
                s=k
                time.sleep(0.5)
                if diff[0]==0 and diff[1]==0:
                    k+=1
                else:
                    s=k
                if k==s:
                    break    
            if k==2:
                p=“\n网络可能已经断开!“
        else:
            p=‘空闲‘
        
        #message=‘↑{0[0]:#f} KBytes/s\n↓{0[1]:#f}kbytes/s‘
        #message=message.format(diff)+p
        return(diff[0]diff[1]p)
root=Tk()
‘‘‘
root.overrideredirect(True)
root.attributes(‘-alpha‘0.9)
root.attributes(‘-topmost‘1)
‘‘‘
root.title(‘实时网络流量监控‘

评论

共有 条评论