美文网首页
创建一个简易PySide2 对话框程序

创建一个简易PySide2 对话框程序

作者: 技术喵 | 来源:发表于2019-07-24 15:48 被阅读0次

1.创建Form类,继承QDialog

import sys
from PySide2.QtWidgets import (QApplication, QDialog, QLineEdit, QPushButton,
    QVBoxLayout, QDialog)

class Form(QDialog):

    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.setWindowTitle("我的窗口")

        #创建窗口
        self.edit = QLineEdit("输入我的名字")
        self.button = QPushButton("显示问候")

        #创建布局
        layout = QVBoxLayout()
        layout.addWidget(self.edit)
        layout.addWidget(self.button)

        #设置布局
        self.setLayout(layout)

        #关联信号槽
        self.button.clicked.connect(self.greetings)

    def greetings(self):
        print ("欢迎 %s" % self.edit.text())


if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    # Create and show the form
    form = Form()
    form.show()
    # Run the main Qt loop
    sys.exit(app.exec_())

2.程序画面


1563954197577.png

3.log输出

欢迎 输入我的名字
欢迎 技术喵

相关文章

网友评论

      本文标题:创建一个简易PySide2 对话框程序

      本文链接:https://www.haomeiwen.com/subject/fggxrctx.html