pyqt5 - 按下按钮时创建按钮
问题描述
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 更新,但对我没有任何帮助。
解决方案
推荐阅读
- python - 更改回收视图列宽
- javascript - 如何使用单色元素的动画背景
- python - 在 Python 中查找字符串中的确切子字符串
- excel - 使用非活动工作表的 Vba 组合框
- c# - 带有 MVVM 绑定的 JQuery Kendo UI Grid 上重新排序的列的状态持久性
- javascript - 将字符串格式的 html 元素附加到元素中在元素周围添加双引号
- wpf - 如果传递长消息,则根本不显示 WPF MessageBox
- mongodb - BSON`_id`与字符串`id`的MongoDB索引策略?
- chef-infra - 在 Solaris 上安装 chef-dk & Inspec
- html - 以指定大小将 HTML Canvas (w/ Fabric.js) 输出为 PDF