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_())
复制代码

 

posted @   c语言我的最爱  阅读(3747)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示