Jul-12-2019, 05:13 PM
(Jul-02-2019, 05:01 PM)LavaCreeperKing Wrote: I think I asked this before, but I was unable to get an answer. I need to know how I can add widgets to my window after it has been created.rom PyQt5 import QtCore, QtGui, QtWidgets import sys, random class window(QtWidgets.QMainWindow): def setup(self): self.resize(300,300) self.setMaximumSize(300, 300) self.setMinimumSize(300, 300) self.button = QtWidgets.QPushButton(self) self.button.setGeometry(QtCore.QRect(50, 80, 121, 41)) self.button.clicked.connectself.addB) def addB(self): y = random.randint(2, 200) b = QtWidgets.QPushButton(self) b.setGeometry(QtCore.QRect(50, y, 121, 41))The code here will create the first button when I call window.setup() and I see it when I call window.show() to make the window show, but I can't figure out how to add objects to the window after that. What I would like to do is create buttons, and add them to a list. That way I can save them, and load them again when I restart the program.
I am just guessing. Will it be fine if you use something like this:
button.show()