from ctypes import WinDLL
import struct


user32 = WinDLL('user32.dll')

def get_res():
    x,y = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
    return "{}x{}".format(x,y)


def set_res(width, height, bpp=32):
    DM_BITSPERPEL = 0x00040000
    DM_PELSWIDTH = 0x00080000
    DM_PELSHEIGHT = 0x00100000
    CDS_UPDATEREGISTRY = 0x00000001
    SIZEOF_DEVMODE = 148

    DevModeData = struct.calcsize("32BHH") * '\x00'
    DevModeData += struct.pack("H", SIZEOF_DEVMODE)
    DevModeData += struct.calcsize("H") * '\x00'
    dwFields = (width and DM_PELSWIDTH or 0) | (height and DM_PELSHEIGHT or 0) | (bpp and DM_BITSPERPEL or 0)
    DevModeData += struct.pack("L", dwFields)
    DevModeData += struct.calcsize("l9h32BHL") * '\x00'
    DevModeData += struct.pack("LLL", bpp or 0, width or 0, height or 0)
    DevModeData += struct.calcsize("8L") * '\x00'
    result = user32.ChangeDisplaySettingsA(DevModeData, CDS_UPDATEREGISTRY)
    return result == 0  # success if zero, some failure otherwise


print(get_res())
set_res(1920, 1080)
print(get_res())