我想更改我所有子窗口中的对象这是我的代码
import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
count = 0
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)
bar = self.menuBar()
file = bar.addMenu("Subwindow")
file.addAction("New")
file.addAction("Change Text")
file.triggered[QAction].connect(self.click)
self.setWindowTitle("Multiple window using MDI")
def click(self,action):
print("New sub window")
if action.text() == "New":
MainWindow.count = MainWindow.count + 1
sub = QMdiSubWindow()
sub.setWidget(QTextEdit())
sub.setWindowTitle("subwindow" + str(MainWindow.count))
self.subwindow = self.mdi.addSubWindow(sub)
self.subwindow.show()
self.label3 = QtWidgets.QLabel(sub)
self.label3.setGeometry(10, 80, 500, 10)
self.label3.setText('Default')
self.label3.show()
if action.text() == "Change Text":
for i in self.mdi.subWindowList():
label1 = QtWidgets.QLabel(i)
label1.setGeometry(10,50,500,10)
label1.setText(str(i))
label1.show()
self.label3.setText('TRUE')
print(i)
def main():
app = QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
但它始终是更改https://i.stack.imgur.com/DjZtf.png的最后一个创建订单子窗口
如何更改每个子窗口中的项目?如何使用超过 10 个子窗口更改我想要的子窗口中的文本表?