标签:qwidget you __name__ pytho 接收 hbox load int ini
代码
from PyQt5.QtWidgets import *
import sys
class pushButton(QWidget):
def __init__(self):
super(pushButton,self).__init__()
# 对方法进行调用
self.initUI()
def initUI(self):
# 设置为水平布局
layout=QHBoxLayout()
# 实例化按钮
button1 = QPushButton(‘按钮1‘)
button2 = QPushButton(‘按钮2‘)
button3 = QPushButton(‘关闭‘)
# 设置点击事件
button1.clicked.connect(self.click)
button2.clicked.connect(self.click)
button3.clicked.connect(self.close)
# 设置文本接收框
self.textEdit=QTextBrowser()
# 布局到窗口上
layout.addWidget(button1)
layout.addWidget(button2)
layout.addWidget(button3)
layout.addWidget(self.textEdit)
# 添加布局到布局上
self.setLayout(layout)
def click(self):
# 获取信号与槽
button = self.sender()
print(button.text())
# 获取 TextEdit的被设置的text值
self.textEdit.setText("点击了"+button.text())
if __name__ == ‘__main__‘:
app = QApplication(sys.argv)
main = pushButton()
main.show()
sys.exit(app.exec_())
标签:qwidget you __name__ pytho 接收 hbox load int ini
原文地址:https://www.cnblogs.com/zhuhukang/p/14866206.html