Skip to main content

跨平台自动获取屏幕分辨率(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 桌面分辨率,自动安装依赖)

核心原理

  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 的相关安装日志,直接可用。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

getScreenSize-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

getScreenSize-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for getScreenSize-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae7209e51c76b038b58a31078617c187fcc7fd6d35f9693d80ba286b11c435c7
MD5 126bef1cdb678f86038cc77574ce9572
BLAKE2b-256 983bb83911b09748aba24416dd344efcc9e14b26cf4c0afa4686fc08ef892a15

See more details on using hashes here.

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

Hashes for getScreenSize-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aebdb99d4674f2834cad11974b840925e522e16a336bd50dde68510fdd9cc169
MD5 7794975e9cc8fdf955284e37dac63362
BLAKE2b-256 0a79b63fff1d31997455d8e86870d632114e0052678036413aeca14fb2fa1a44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page