PyQt5基础学习-设置窗口的最大化和最小化 1.self.showMaximized(设置窗口的最大化) 2.self.showMinimized(设置窗口的最小化)
可以通过自定义函数实现窗口的最大化,即self.setGeometry(rect)设置窗口为桌面的尺寸
也可以直接调用系统的程序进行实现
WindowMaxMin.py
""" 用代码控制窗口的最大值和最小值 """ from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * import sys class WindowMaxMin(QWidget): ### 构造函数 def __init__(self, parent=None): """构造函数""" #调用父类构造函数 super(WindowMaxMin, self).__init__() self.resize(300, 400) self.setWindowTitle("用代码控制窗口的最大化和最小化") self.setWindowFlags(Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint) layout = QVBoxLayout() maxButton1 = QPushButton() maxButton1.setText("窗口最大化1") maxButton1.clicked.connect(self.maximized1) maxButton2 = QPushButton() maxButton2.setText("窗口最大化2") #self.showMaximized(最大化操作) maxButton2.clicked.connect(self.showMaximized) maxButton3 = QPushButton() maxButton3.setText("窗口最小化") #self.showMaximized(最大化操作) maxButton3.clicked.connect(self.showMinimized) layout.addWidget(maxButton1) layout.addWidget(maxButton2) layout.addWidget(maxButton3) self.setLayout(layout) def maximized1(self): desktop = QApplication.desktop() #获取桌面可用尺寸 rect = desktop.availableGeometry() self.setGeometry(rect) if __name__ == "__main__": app = QApplication(sys.argv) main = WindowMaxMin() main.show() sys.exit(app.exec_())
每天更新pyQt5内容