PySide2(PyQt5)根据屏幕大小初始化窗口大小
目录
引言:
- PySide2获取屏幕分辨率并设置窗口大小
步骤:
-
1、获取桌面对象desktop,通过桌面对象我们可以获取pc设备的屏幕信息
-
2、对主window重新设置其宽高
class MainWindow(): def __init__(self): self.window = QtWidgets.QMainWindow() self.initSize(0.6) def initSize(self, rate): desktop = QtWidgets.QApplication.desktop() self.screenWidth = desktop.width() * rate self.screenHeight = desktop.height() * rate print("screen width is %d height is %d", (self.screenWidth, self.screenHeight)) self.window.resize(self.screenWidth, self.screenHeight) def show(self): self.window.show if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) mainWin = MainWindow() mainWin.show() sys.exit(app.exec_())
-
更多分享:www.catbron.cn