When I run the code below, it shows the below. Why isn't x 'x' but becomes a boolean? This happens only to the first argument passed into the function called with lambda.
false y /home/me/model/some_file
from PyQt5.QtWidgets import QPushButton
modelpath = '/home/me/model'
filelist = os.listdir(modelpath)
x = 'x'
y = 'y'
def HelloWidget(QWidget):
def __init__(self):
for file in filelist:
button = QPushButton(file)
button.clicked.connect(lambda x=x,y=y,file=file: self.myfunction(x,y,file)
def myfunction(self,x,y,file):
print(x)
print(y)
print(file)
The problem is caused because
clicked
passes a Boolean value indicating whether it has been checked or not. the appropriate thing is to use a parameter to use that argument: