1

i need help with this it's complicated some how ! i try hard before post this i want to store each info text for each button from the loop to pass it throw new function i hope i did explain the problem well

ch_list = [{'icon':'url../img.jpg', 'value':'str', 'info':'text'}, 
       {'icon':'url../img.jpg', 'value':'str', 'info':'text'}, .....]
       # value_1 & value_2 is ignored ..
def put_chan(self, ch_list):
    position = [(i, j) for i in range(len(ch_list)-1) for j in range(4)]

    for ch, position in zip(ch_list, position):
        QApplication.processEvents()
        ch_img = str(ch['icon'])
        data = urllib.request.urlopen(ch_img).read()
        pixmap = QPixmap()
        pixmap.loadFromData(data)
        icon = QIcon(pixmap)
        btn = QPushButton()
        btn.setFixedSize(75, 50)
        btn.setIcon(icon)
        btn.setIconSize(QtCore.QSize(75, 50))
        btn.clicked.connect(lambda x: self.btn_clicked(ch['info']))
        self.grid.addWidget(btn, *position)

def btn_clicked(self, txt):
    print(txt)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • What is the problem? I mean, do you get an error message? Does the code not work as you expect? What is the output you get? As such, you look for `ch['icon']`, `ch['info']`, whereas in the dictionaries, you have `icon_1`, `info_1` etc. Maybe that is the issue. – mahesh Aug 06 '18 at 08:53
  • the outputs of all the buttons are the same , the last 'text' value from the loop, but i need to make every button has a specific 'text' value to pass it as an parameter to btn_clicked function , i forguet to say that the key's from the dict are the same only values are not – Adouani Oualid Aug 07 '18 at 15:05
  • 1
    change to `btn.clicked.connect(lambda x, text=ch['info'] : self.btn_clicked(text))` – eyllanesc Aug 07 '18 at 16:48

0 Answers0