0
def seeEntries(self):
    self.currentEntries = self.working.seeEntries()

    self.cleanAWidget(self.placeToPutEntriesLayout)

    count = 1

    self.placeToPutEntriesLayout.addWidget(QLabel("Email"), 0, 0)
    self.placeToPutEntriesLayout.addWidget(QLabel("Website"), 0, 1)
    self.placeToPutEntriesLayout.addWidget(QLabel(""), 0, 2)
    self.buttonsToSee = []

    for i in range(len(self.currentEntries)):
        countV = 0
        for j in self.currentEntries[i]:
            self.placeToPutEntriesLayout.addWidget(QLabel(text = j), count, countV)
            countV += 1
        self.buttonsToSee.append(QPushButton("Get this entry"))
        self.buttonsToSee[i].clicked.connect(lambda : self.getPasswordFromButton(self.currentEntries[i])
        self.placeToPutEntriesLayout.addWidget(self.buttonsToSee[-1], count, countV)
        countV += 1

        count += 1

    self.workingPage.hide()
    self.seeEntriesPage.show()

I am trying to make a Simple Password Manager GUI project with PyQt5 but facing some weird problems with Buttons.

Code: https://github.com/HetDaftary/Python-Projects/tree/master/Simple-Password-Manager

I am trying to add a feature to see the entries with Buttons from the See entries page in the update but every time I try to press a button, it gives the result like the last button was pressed.

The See Entries page

So, Here a button should ideally get the entry for i-th current entry. And the but it passes the last entry from currentEntries.

  • Try `lambda i=i: self.getPasswordFromButton(self.currentEntries[i])` – alec Apr 05 '21 at 06:48
  • 2
    @alec you would need `lambda _, i=i:...`. `QPushButton.clicked` emits the `checked` state of the button which will be assigned to the the first parameter of the slot (if present). – Heike Apr 05 '21 at 07:05

0 Answers0