osdir.com


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

Pyqt5 help


On 01/02/2020 12:06, Souvik Dutta wrote:

> not happening. Now the no. Of labels depend upon something, so I decided to
> use a for loop which is not working. Attaching the code below. Can you help?

I just spotted something else odd in your code:


  def initUi(self):
       ...
       self.n = {}

self.n is a dictionary.... maybe self.friends would be a better name?

    def save(self):
        self.friend_name = self.Namefield.text()
        self.friend_date = self.Datefield.text()
        self.n[self.friend_name] = self.friend_date

And here you add a new value from your UI fields

        for a in self.n:

Now you iterate over the dictionary creating a label
for each entry in the dict but...

            NewLabel = QtWidgets.QLabel(self)
            NewLabel.setText(self.friend_name + "has birthday on " +
self.friend_date)
            NewLabel.setGeometry(QtCore.QRect(30, 250, 100, 100))

The labels all have the name of the most recent friend?
And they all have the same geometry, so presumably sit
on top of each other?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos