📜  python screeninfo - Python (1)

📅  最后修改于: 2023-12-03 15:19:00.112000             🧑  作者: Mango

Python Screeninfo

Introduction

Python Screeninfo is a library used to get information about the screens connected to a computer. It returns properties like screen size, resolution, and refresh rate. This information is useful when developing applications that need to adjust to different screen sizes or supported refresh rates.

Installation

To install Python Screeninfo, open a terminal and enter the following command:

pip install screeninfo
Usage

To use Python Screeninfo, import the module and call the get_monitors() function. This function returns a list of Monitor objects, each object containing information about a connected screen.

from screeninfo import get_monitors

monitors = get_monitors()

for m in monitors:
    print("Monitor {}:".format(m.name))
    print("\tSize (mm): {}, {}".format(m.width_mm, m.height_mm))
    print("\tResolution: {},{}".format(m.width, m.height))
    print("\tRefresh rate: {}".format(m.refresh_rate))

The code snippet above prints information about all connected screens.

Additional Properties

In addition to the properties displayed above, Monitor objects also contain information about screen position, orientation, and DPI scaling. This information is available through the following properties:

  • x: X-coordinate of the top-left corner of the screen.
  • y: Y-coordinate of the top-left corner of the screen.
  • is_primary: Returns True if the screen is the primary screen.
  • orientation: Orientation of the screen (Portrait, PortraitFlipped, Landscape, or LandscapeFlipped).
  • dpi: DPI scaling of the screen.
Conclusion

Python Screeninfo is a useful library for getting information about connected screens. Developers can use this information to create applications that adjust their layout, size, and refresh rate based on the screen properties of the current system.