PyQt基础_010_对话框类控件QDialog

基本案例

PyQt基础_010_对话框类控件QDialog_第1张图片

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_())

按钮改为接收,拒绝,完成

PyQt基础_010_对话框类控件QDialog_第2张图片

import sys

from PyQt5.Qt import *

# 1. 创建一个应用程序对象
app = QApplication(sys.argv)

# 2.控件的操作
# 2.1创建控件
window = QWidget()
# 2.2设置控件

window.setWindowTitle("QDialog")
window.resize(500, 500)
window.move(400, 250)

d = QDialog(window)
d.setWindowTitle("对话框")

btn1 = QPushButton("accept", d)
btn1.move(100, 20)
btn1.clicked.connect(lambda: d.accept())
btn2 = QPushButton("reject", d)
btn2.move(200, 20)
btn2.clicked.connect(lambda: d.reject())
btn3 = QPushButton("done", d)
btn3.move(300, 20)
btn3.clicked.connect(lambda: d.done(8))

d.accepted.connect(lambda: print("点击了接受按钮"))
d.rejected.connect(lambda: print("点击了拒绝按钮"))
d.finished.connect(lambda val: print("完成", val))

d.show()

# 2.3展示控件
window.show()

# 3.应用程序的执行, 进入到消息循环
sys.exit(app.exec_())

你可能感兴趣的:(PyQt,pyqt,数据库)