How do I get monitor resolution in Python?

后端 未结 30 1020
深忆病人
深忆病人 2020-11-22 13:49

What is the simplest way to get monitor resolution (preferably in a tuple)?

30条回答
  •  有刺的猬
    2020-11-22 14:26

    It's a little troublesome for retina screen, i use tkinter to get the fake size, use pilllow grab to get real size :

    import tkinter
    root = tkinter.Tk()
    resolution_width = root.winfo_screenwidth()
    resolution_height = root.winfo_screenheight()
    image = ImageGrab.grab()
    real_width, real_height = image.width, image.height
    ratio_width = real_width / resolution_width
    ratio_height = real_height/ resolution_height
    

提交回复
热议问题