PyQt5学习之路,点击有pyqt5学习笔记
QDialog是对话框类控件,PyQt5种定义了一系列的标准对话框类。
QMessageBox
:用来显示消息对话框QColorDialog
:颜色对话框QFileDialog
:用来打开和保存文件的对话框QFontDialog
:用来改变字体的对话框QInputDialog
:用来收集输入信息
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class QDialogDemo(QMainWindow):
def __init__(self):
super(QDialogDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('QDialog')
self.resize(300, 300)
self.button = QPushButton(self)
self.button.setText('弹出对话框')
self.button.move(50, 50)
self.button.clicked.connect(self.showDialog)
def showDialog(self):
dialog = QDialog()
button = QPushButton('确定', dialog)
button.clicked.connect(dialog.close)
button.move(50, 50)
dialog.setWindowTitle('对话框')
dialog.setWindowModality(Qt.ApplicationModal)
dialog.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QDialogDemo()
main.show()
sys.exit(app.exec_())
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/92bfd89e63d441fbe8d9ad9119370710.png)