zoukankan      html  css  js  c++  java
  • 内置窗口 pyqt5

    内置窗口 pyqt5

     

    1.使用Qt Designer设计三个窗口

    注意:在主窗口中需要添加一个girdLayout

    2.创建**.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    from PyQt5.QtWidgets import QMainWindow, QApplication
    from main import Ui_Main
    from show import Ui_Show
    from new import Ui_New
    import sys
      
    class Main(QMainWindow,Ui_Main):
        def __init__(self):
            super(Main,self).__init__()
            self.setupUi(self)
            self.child1 = Show()
            self.child2 = New()
            self.action_2.triggered.connect(self.New)
            self.action.triggered.connect(self.Show)
        def Show(self):
            self.gridLayout.addWidget(self.child1)#将窗口放入girdLayout中
            self.child1.show()#打开子窗口1
        def New(self):
            self.gridLayout_2.addWidget(self.child2)
            self.child2.show()
      
    class New(QMainWindow,Ui_New):
        def __init__(self):
            super(New,self).__init__()
            self.setupUi(self)
            self.pushButton.clicked.connect(self.Close)
        def Close(self):
            self.close()
      
    class Show(QMainWindow,Ui_Show):
        def __init__(self):
            super(Show,self).__init__()
            self.setupUi(self)
      
    if __name__=='__main__':
        app = QApplication(sys.argv)
        Main = Main()
        Show = Show()
        New = New()
        Main.show()
        sys.exit(app.exec_())

      

    3.在主窗口里有两个选项(“初始”和“新建”)与两个子窗口关联

    4.“初始”打开

    5.“新建”打开

    ###############################################

    小技巧

    发现出现了两个底边那个东西

    在由窗口文件生成的.py文件中找到如下代码

    1
    2
    3
    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)

      

    或者在Qt Designer设计时找到

    删掉任意一个就OK了

  • 相关阅读:
    [Makefile] 递归编译的Makefile的实现
    python中出现 IndentationError:unindent does not match any outer indentation level
    Python3 编译中文字串报错解决方案
    linux下创建和删除软、硬链接
    免费的编程中文书籍索引
    starUML建立时序图
    UML 学习地址
    使用 Addr2line 将函数地址解析为函数名
    WIFI基本知识整理
    Ubuntu16.04 安装Python3.6 报错
  • 原文地址:https://www.cnblogs.com/valorchang/p/11399909.html
Copyright © 2011-2022 走看看