制作一个快速打印电脑配置及内存/磁盘等使用情况的小工具!

在电脑使用过程中,为了获取基本配置以及内存使用等的操作情况,需要手动的查看或打开任务管理器来查看。

为了能够在查看这些信息时比较方便,于是使用python做了一个简易的exe桌面应用。在需要时双击打开即可随时获取这些信息。

以下应用的开发主要使用了loguru/wmi/psutil三个主要的python非标准库,可以选择使用pip的方式进行安装。

pip install loguru

pip install wmi

pip install psutil

然后,将需要的模块全部导入进来,下面的英文注释都是使用Pycharm AI插件自动生成的。

# It's a logger.
from loguru import logger

# It's a Python module that allows you to connect to Windows Management Instrumentation (WMI) and query system
# information.
import wmi

# It's a Python module that allows you to connect to Windows Management Instrumentation (WMI) and query system
# information.
import psutil as pt

1.使用python非标准库wmi获取电脑三大配置的主要信息,直接打印出来。

logger.info('电脑基本配置信息!!!')

pc_ = wmi.WMI()
os_info = pc_.Win32_OperatingSystem()[0]
processor = pc_.Win32_Processor()[0]
gpu = pc_.Win32_VideoController()[0]
os_name = os_info.Name.encode('utf-8').split(b'|')[0]
ram = float(os_info.TotalVisibleMemorySize) / 1024 / 1024

logger.info('操作系统信息:{}'.format(os_name))
logger.info('CPU信息:{}'.format(processor.Name))
logger.info('系统运行内存:{} GB'.format(ram))
logger.info('显卡信息:{}'.format(gpu.Name))

2.使用python非标准库psutil模块获取CPU/内存/磁盘等信息,直接打印出来。

logger.info('电脑使用过程信息!!!')

memory_info = pt.virtual_memory()
logger.info('电脑运行内存总大小:{} GB'.format(round(float(memory_info.total / 1024 / 1024 / 1024), 2)))
logger.info('电脑已使用内存大小:{} GB'.format(round(float(memory_info.used / 1024 / 1024 / 1024), 2)))
logger.info('电脑空闲内存大小:{} GB'.format(round(float(memory_info.free / 1024 / 1024 / 1024), 2)))

logger.info('cpu核数:{}'.format(pt.cpu_count()))

disk_usage = pt.disk_usage('/')
logger.info('磁盘总空间:{} GB'.format(round(float(disk_usage.total / 1024 / 1024 / 1024), 2)))
logger.info('磁盘已使用空间:{} GB'.format(round(float(disk_usage.used / 1024 / 1024 / 1024), 2)))
logger.info('磁盘可用空间:{} GB'.format(round(float(disk_usage.free / 1024 / 1024 / 1024), 2)))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/chengxuyuan_110/article/details/129539851
今日推荐