import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
################################################
#######创建主窗口
################################################
class FirstMainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('主界面') ###### 创建界面 ######
self.centralwidget = QWidget()
self.setCentralWidget(self.centralwidget)
self.Layout = QVBoxLayout(self.centralwidget) # 设置顶部三个按钮
self.topwidget = QWidget()
self.Layout.addWidget(self.topwidget)
self.buttonLayout = QHBoxLayout(self.topwidget) self.pushButton1 = QPushButton()
self.pushButton1.setText("打开主界面")
self.buttonLayout.addWidget(self.pushButton1) self.pushButton2 = QPushButton()
self.pushButton2.setText("打开对话框")
self.buttonLayout.addWidget(self.pushButton2) self.pushButton3 = QPushButton()
self.pushButton3.setText("打开提示框")
self.buttonLayout.addWidget(self.pushButton3) # 设置中间文本
self.label = QLabel()
self.label.setText("第一个主界面")
self.label.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
self.label.setAlignment(Qt.AlignCenter)
self.label.setFont(QFont("Roman times", 50, QFont.Bold))
self.Layout.addWidget(self.label) # 设置状态栏
self.statusBar().showMessage("当前用户:一心狮") # 窗口最大化
self.showMaximized() ###### 三个按钮事件 ######
self.pushButton1.clicked.connect(self.on_pushButton1_clicked)
self.pushButton2.clicked.connect(self.on_pushButton2_clicked)
self.pushButton3.clicked.connect(self.on_pushButton3_clicked) # 按钮一:打开主界面
windowList = []
def on_pushButton1_clicked(self):
the_window =SecondWindow()
self.windowList.append(the_window) ##注:没有这句,是不打开另一个主界面的!
self.close()
the_window.show() # 按钮二:打开对话框
def on_pushButton2_clicked(self):
the_dialog = TestdemoDialog()
if the_dialog.exec_() == QDialog.Accepted:
pass # 按钮三:打开提示框
def on_pushButton3_clicked(self):
QMessageBox.information(self, "提示", "这是information框!")
#QMessageBox.question(self, "提示", "这是question框!")
#QMessageBox.warning(self, "提示", "这是warning框!")
#QMessageBox.about(self, "提示", "这是about框!") ################################################
#######第二个主界面
################################################
class SecondWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('第二主界面') # 设置中间文本
self.label = QLabel()
self.label.setText("第二个主界面")
self.label.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
self.label.setAlignment(Qt.AlignCenter)
self.label.setFont(QFont("Roman times", 50, QFont.Bold))
self.setCentralWidget(self.label) # 设置状态栏
self.statusBar().showMessage("当前用户:一心狮") # 窗口最大化
self.showMaximized() ###### 重写关闭事件,回到第一界面
windowList = []
def closeEvent(self, event):
the_window = FirstMainWindow()
self.windowList.append(the_window) ##注:没有这句,是不打开另一个主界面的!
the_window.show()
event.accept() ################################################
#######对话框
################################################
class TestdemoDialog(QDialog):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('对话框') ### 设置对话框类型
self.setWindowFlags(Qt.Tool) ################################################
#######程序入门
################################################
if __name__ == "__main__":
app = QApplication(sys.argv)
the_mainwindow = FirstMainWindow()
the_mainwindow.show()
sys.exit(app.exec_())

最新文章

  1. 11i和R12配置JAR包
  2. jQuery 学习笔记(函数调用机制)
  3. Postman-CI集成Jenkins
  4. paip.输入法编程---词库多意义条目分割 python实现.
  5. 谷歌面经 Tree Serialization
  6. static inline
  7. ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)
  8. enable ide
  9. poI地址纠偏查询存储过程理解
  10. CentOS 6.2 二进制安装apache2.4.3出现configure: error: APR-util not found. Please read the documentation的解决方
  11. 黑马程序员:轻松精通Java学习路线连载1-基础篇!
  12. 关于InnoDB存储引擎text和blob类型的优化
  13. 使用wwise音效引擎的好处
  14. pycharm 下的djiango使用
  15. 打开RAD Studio XE5提示"displayNotification:内存不够"解决办法
  16. windows10操作系统中cmd窗口下telnet功能失效的解决方案
  17. missing gradle project information
  18. 【Coursera】Technology :Fifth Week(1)
  19. leetcode动态规划
  20. s3c2440中断控制器操作

热门文章

  1. HttpClient(五)-- 模拟表单上传文件
  2. NFS exportfs 命令
  3. HttpClient 通信工具类
  4. 禁用Visual Studio 2013的Browser Link功能 -调试不断请求http://localhost:6154/c4ad1c693ebf428283832eaa827f9c6e/arterySignalR/poll?transport=longPolling...
  5. 【EF框架异常】System.MissingMethodException:“找不到方法:“System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration
  6. 原生js--类、原型、构造函数
  7. router之switch
  8. 题目1013:开门人和关门人(结构体自定义cmp排序)
  9. [转]Linux sendmail 详解
  10. 利用开源架构ELK构建分布式日志系统