对话框QDialog

介绍

QDialog类的子类主要有QMessageBox、QFileDialog、QFontDialog、QInputDialog等。

方法

方法 描述
setWindowTitle() 设置对话框标题
setWIndowModality() 设置窗口模态。取值如下:
Qt.NonModal,非模态,可以和程序的其他窗口交互
Qt.WindowModel,窗口模态,程序在未处理完当前对话框时,将阻止和对话框的父窗口进行交互
Qt.ApplicationModal,应用程序模态,阻止和任何其他窗口进行交互

QDialog的使用

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class DialogDemo(QMainWindow):

	def __init__(self,parent=None):
		super(DialogDemo,self).__init__(parent)
		self.setWindowTitle("Dialog例子")
		self.resize(350,300)

		self.btn = QPushButton(self)
		self.btn.setText("弹出对话框")
		self.btn.move(50,50)
		self.btn.clicked.connect(self.showdialog)

	def showdialog(self):
		dialog = QDialog()
		btn = QPushButton("OK",dialog)
		btn.move(50,50)
		dialog.setWindowTitle("Dialog")
		dialog.setWindowModality(Qt.ApplicationModal)
		dialog.exec_()

if __name__ == "__main__":
	app = QApplication(sys.argv)
	demo = DialogDemo()
	demo.show()
	sys.exit(app.exec_())

使用展示

对话框QDialog_第1张图片

后记

会话框的基类,新的一天又要来了。

你可能感兴趣的:(#,PyQt5,PyQt5)