pyqt5獲取顯示器的解析度
阿新 • • 發佈:2018-11-11
程式碼如下
import sys from PyQt5.QtWidgets import QApplication, QWidget class Example(QWidget): def __init__(self): super().__init__() self.initUI() # 介面繪製交給InitUi方法 def initUI(self): self.desktop = QApplication.desktop() #獲取顯示器解析度大小 self.screenRect = self.desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() print(self.height) print(self.width) # 顯示視窗 self.show() if __name__ == '__main__': # 建立應用程式和物件 app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())