zoukankan      html  css  js  c++  java
  • pyqt对话框

     1 import sys
     2 from PyQt5.QtCore import *
     3 from PyQt5.QtGui import *
     4 from PyQt5.QtWidgets import *
     5 class MyWindow(QWidget):
     6  def __init__(self,parent=None):
     7  super(MyWindow,self).__init__(parent)
     8  self.setWindowTitle("弹出式对话框例子")
     9  self.resize(400,200)
    10  self.btn1=QPushButton(self)
    11  self.btn1.setText("消息框")
    12  self.btn1.clicked.connect(self.msg1)
    13  layout=QVBoxLayout()
    14  
    15  self.btn2=QPushButton(self)
    16  self.btn2.setText("问答对话框")
    17  self.btn2.clicked.connect(self.msg2)
    18  
    19  self.btn3=QPushButton()
    20  self.btn3.setText("警告对话框")
    21  self.btn3.clicked.connect(self.msg3)
    22  
    23  self.btn4=QPushButton()
    24  self.btn4.setText("严重错误对话框")
    25  self.btn4.clicked.connect(self.msg4)
    26  
    27  self.btn5=QPushButton()
    28  self.btn5.setText("关于对话框")
    29  self.btn5.clicked.connect(self.msg5)
    30  
    31  layout.addWidget(self.btn1)
    32  layout.addWidget(self.btn2)
    33  layout.addWidget(self.btn3)
    34  layout.addWidget(self.btn4)
    35  layout.addWidget(self.btn5)
    36  
    37  self.setLayout(layout)
    38  
    39   
    40  def msg1(self):
    41  #使用infomation信息框
    42  QMessageBox.information(self,"标题","消息正文",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
    43  def msg2(self):
    44   QMessageBox.question(self,"标题","问答消息正文",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
    45  def msg3(self):
    46  QMessageBox.warning(self,"标题","警告消息正文",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
    47  def msg4(self):
    48  QMessageBox.critical(self,"标题","严重错误消息正文",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
    49  def msg5(self):
    50  QMessageBox.about(self,"标题","关于消息正文")
    51  
    52 if __name__=="__main__":
    53  app=QApplication(sys.argv)
    54  win=MyWindow()
    55  win.show()
    56  sys.exit(app.exec_())
  • 相关阅读:
    [ACM] hdu 1848 Fibonacci again and again(Nim博弈 SG函数)
    [ACM] hdu 2176 取(m堆)石子游戏(Nim博弈)
    [ACM] hdu 1850 Being a Good Boy in Spring Festival(Nim博弈)
    母函数
    Euclid算法(欧几里得算法)
    Poj 2533
    Poj 1836
    Poj 3267
    hdu 1878
    poj 3349
  • 原文地址:https://www.cnblogs.com/xiaochi/p/11564796.html
Copyright © 2011-2022 走看看