How do I get monitor resolution in Python?

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

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

30条回答
  •  情歌与酒
    2020-11-22 14:42

    In case you have PyQt4 installed, try the following code:

    from PyQt4 import QtGui
    import sys
    
    MyApp = QtGui.QApplication(sys.argv)
    V = MyApp.desktop().screenGeometry()
    h = V.height()
    w = V.width()
    print("The screen resolution (width X height) is the following:")
    print(str(w) + "X" + str(h))
    

    For PyQt5, the following will work:

    from PyQt5 import QtWidgets
    import sys
    
    MyApp = QtWidgets.QApplication(sys.argv)
    V = MyApp.desktop().screenGeometry()
    h = V.height()
    w = V.width()
    print("The screen resolution (width X height) is the following:")
    print(str(w) + "X" + str(h))
    

提交回复
热议问题