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输出
欢迎 输入我的名字
欢迎 技术喵
网友评论