[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pyqt5 help

On 01/02/2020 12:06, Souvik Dutta wrote:
> I was making a pyqt5 project and I ran into a problem. I want a button in
> one window to add a label in another window when clicked upon. But that is
> not happening.

What is happening? Don't expect us to run your buggy code!

>  Now the no. Of labels depend upon something, so I decided to
> use a for loop which is not working.

Looking at the code I see:

for a in self.n:
    NewLabel = QtWidgets.QLabel(self)
    NewLabel.setText(self.friend_name + "has birthday on " +
    NewLabel.setGeometry(QtCore.QRect(30, 250, 100, 100))

I'm no Qt expert but it seems that you are overwriting the same widget
(or widget location?) with all of the labels? And all of the labels are
identical since you use the same data to create them?

I would expect something more like (pseudo code!):

for a in self.n:
    newLabel = QtWidgets.QLabel(self)
    NewLabel.setText(self.friends[a].friend_name + "has birthday on " +
    self.friendLabels.append(newLabel)   # if you need a reference

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at: