代码可直接运行
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QFrame
import sys
class ui(QWidget):
def __init__(self):
super().__init__()
self.dict = {}
self.add = QPushButton(self)
self.add.setText('添加')
self.add.setGeometry(50, 50, 100, 50)
self.add.clicked.connect(self.BottonPressEvent)
self.index = 0
def show_ui(self):
self.dict["botton"+str(self.index)] = QPushButton(self)
self.dict["botton"+str(self.index)].setText("botton"+str(self.index))
self.dict["botton"+str(self.index)].setGeometry(50, 100 + 50*self.index, 100, 50)
return self.dict["botton"+str(self.index)]
def BottonPressEvent(self):
self.show_ui().setVisible(True)
self.index += 1
print('你是天才')
if __name__=='__main__':
app = QApplication(sys.argv)
u = ui()
u.show()
sys.exit(app.exec_())
成功界面