Skip to main content

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 桌面分辨率,自动安装依赖)

核心原理

  1. 条件依赖:
    在 setup.py 中通过 sys.platform 判断系统,仅当为 Linux 时,将 python3-xlib 添加到 install_requires 列表。
    这样执行 pip install getScreenSize 时:

    • Linux 环境:pip 会自动下载并安装 python3-xlib。
    • Windows 环境:不安装该依赖,避免冗余。
  2. 容错处理:
    即使自动安装失败(如网络问题),core.py 中仍保留手动安装的提示,确保用户有备选方案。

测试验证

  1. Linux 系统:
    执行 pip install .(本地安装)或 pip install screensize(PyPI 安装),会看到日志中自动安装 python3-xlib。

  2. Windows 系统:
    安装时不会出现 python3-xlib 的相关安装日志,直接可用。

Metadata

Release files for getScreenSize 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for getScreenSize 0.1.1
File Size Uploaded Provenance Actions
getScreenSize-0.1.1.tar.gz 3.0 kB Without provenance Details for getScreenSize-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for getScreenSize 0.1.1
File Interpreter ABI Platform Actions
getScreenSize-0.1.1-py3-none-any.whl Python 3 none any Details for getScreenSize-0.1.1-py3-none-any.whl

Total release size: 7.1 kB

Release files / getScreenSize-0.1.1.tar.gz

Download URL getScreenSize-0.1.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ae7209e51c76b038b58a31078617c187fcc7fd6d35f9693d80ba286b11c435c7
BLAKE2b-256 checksum
How to use checksums
983bb83911b09748aba24416dd344efcc9e14b26cf4c0afa4686fc08ef892a15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / getScreenSize-0.1.1-py3-none-any.whl

Download URL getScreenSize-0.1.1-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aebdb99d4674f2834cad11974b840925e522e16a336bd50dde68510fdd9cc169
BLAKE2b-256 checksum
How to use checksums
0a79b63fff1d31997455d8e86870d632114e0052678036413aeca14fb2fa1a44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for getScreenSize 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page