Is there a cross platform way to get the monitor's refresh rate in python (2.6)? I'm using Pygame and PyOpenGL, if that helps.
I don't need to change the refresh rate, I just need to know what it is.
Is there a cross platform way to get the monitor's refresh rate in python (2.6)? I'm using Pygame and PyOpenGL, if that helps.
I don't need to change the refresh rate, I just need to know what it is.
I am not sure about the platform you use, but on window you can use ctypes or win32api to get details about devices e.g. using win32api
import win32api
def printInfo(device):
print((device.DeviceName, device.DeviceString))
settings = win32api.EnumDisplaySettings(device.DeviceName, -1)
for varName in ['Color', 'BitsPerPel', 'DisplayFrequency']:
print("%s: %s"%(varName, getattr(settings, varName)))
device = win32api.EnumDisplayDevices()
printInfo(device)
output on my system:
\\.\DISPLAY1 Mobile Intel(R) 945GM Express Chipset Family
Color: 0
BitsPerPel: 8
DisplayFrequency: 60
On macOS, you can use pyobjc
to query the refresh rate of all the attached displays. You'll need the Cocoa
(i.e. "AppKit") framework for this:
$ python3 -m venv screen-res
$ . ./screen-res/bin/activate
$ pip install pyobjc-framework-Cocoa
then, in Python:
from AppKit import NSScreen
for each in NSScreen.screens():
print(f"{each.localizedName()}: {each.maximumFramesPerSecond()}Hz")
On my system, this produces:
LG HDR WQHD+: 120Hz
Built-in Retina Display: 120Hz
(Which is correct, my displays are indeed both set to a 120Hz refresh rate.)