跨平台自动获取屏幕分辨率(Linux 自动安装依赖)
Project description
Python-getScreenSize
跨平台自动获取屏幕分辨率的 Python 库,支持 Windows 和 Linux 系统。
安装
pip install getScreenSize
说明:
- Linux 系统会自动安装依赖
python3-xlib,无需手动操作。 - Windows 系统无额外依赖。
使用示例
from getScreenSize import get_screen_size
try:
width, height = get_screen_size()
print(f"屏幕分辨率:{width}x{height}")
except Exception as e:
print(f"获取失败:{e}")
支持的系统
- Windows(通过
ctypes调用系统 API) - Linux(通过
Xlib库获取 X11 桌面分辨率,自动安装依赖)
核心原理
-
条件依赖:
在setup.py中通过sys.platform判断系统,仅当为 Linux 时,将python3-xlib添加到install_requires列表。
这样执行pip install getScreenSize时:- Linux 环境:pip 会自动下载并安装
python3-xlib。 - Windows 环境:不安装该依赖,避免冗余。
- Linux 环境:pip 会自动下载并安装
-
容错处理:
即使自动安装失败(如网络问题),core.py中仍保留手动安装的提示,确保用户有备选方案。
测试验证
-
Linux 系统:
执行pip install .(本地安装)或pip install screensize(PyPI 安装),会看到日志中自动安装python3-xlib。 -
Windows 系统:
安装时不会出现python3-xlib的相关安装日志,直接可用。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file getScreenSize-0.1.1.tar.gz.
File metadata
- Download URL: getScreenSize-0.1.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae7209e51c76b038b58a31078617c187fcc7fd6d35f9693d80ba286b11c435c7
|
|
| MD5 |
126bef1cdb678f86038cc77574ce9572
|
|
| BLAKE2b-256 |
983bb83911b09748aba24416dd344efcc9e14b26cf4c0afa4686fc08ef892a15
|
File details
Details for the file getScreenSize-0.1.1-py3-none-any.whl.
File metadata
- Download URL: getScreenSize-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aebdb99d4674f2834cad11974b840925e522e16a336bd50dde68510fdd9cc169
|
|
| MD5 |
7794975e9cc8fdf955284e37dac63362
|
|
| BLAKE2b-256 |
0a79b63fff1d31997455d8e86870d632114e0052678036413aeca14fb2fa1a44
|