So, I'm relatively new to Python, and I was trying to learn PyQt. I wanted to create a menu dynamically based on the contents of the list. I found an example that I adapted, and it looked like this:
for someText in myList: entry = QAction(someText,MainWindow) self.myMenu.addAction(entry) entry.triggered.connect(lambda menuItem=someText: self.doStuff(menuItem)) entry.setText(someText)
A menu was created, but when a menu item was selected, doStuff () always gets the value False. So I changed this:
for someText in myList: entry = QAction(someText,MainWindow) self.myMenu.addAction(entry) entry.triggered.connect(lambda bVal, menuItem=someText: self.doStuff(bVal,menuItem)) entry.setText(someText)
and, of course, everything works as we would like. I still get False in bVal, which I just ignore.
I tried to look at the PyQt documentation, but the link refers to the C ++ documentation, and this is not obvious to me from what is happening.
I would like to understand what a logical value is and why, in my case, it is always False. I tried to change different things, but I could not find the script where it is True.
thanks
PyQT5.4, Python 3.4.2 on Windows.
python pyqt5 pyqt
Paulm
source share