Python GUI的新手。我正在创建一个小程序,其中 有一个按钮,当我按下它时,它应该在其中创建另一个按钮 GUI。
尝试过:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'PyQt5 Pet Project'
self.left = 10
self.top = 10
self.width = 1000
self.height = 700
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Create a button in the window
self.buttonA = QPushButton('Simple If', self)
self.buttonA.move(10, 10)
# connect button to function on_click
self.buttonA.clicked.connect(self.on_click)
self.show()
def on_click(self):
# Need to create a button here , only if buttonA is pressed
self.buttonB = QPushButton('Simple If', self)
self.buttonB.move(200, 10)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
但是它没有更新GUI中的任何内容。搜索GUI更新 同样,但对我没有任何帮助。