i want ask a simple question. i have 2 classes. i got many functions. i keep functions on class operationsOnFiles()
, and ui elements on class UI_MainWindow(object)
. i use a btnSetRandomWallpaper
button call settingRandomWallpaper()
function with liste
argument and it didnt work. so i used lambda
there. then it works. i tried to do same thing with my other function updateList()
. it doesnt have any argument. same errors and i used lambda
there too. no error but no action too. am i missing a point? or something?
class operationsOnFiles():
def settingRandomWallpaper(self, liste):
super().__init__()
selectedWallpaper = random.choice(liste)
os.system("gsettings set org.gnome.desktop.background picture-uri /home/$USER/Projects/src/" + selectedWallpaper)
def updateList():
super().__init__()
Ui_MainWindow.listWidget.addItems(selfish.wallpapers)
selfish = operationsOnFiles()
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.btnSetRandomWallpaper.clicked.connect(lambda: selfish.settingRandomWallpaper(selfish.wallpapers))
self.btnUpdateList.clicked.connect(lambda: operationsOnFiles.updateList)
The connect
event is called without parameters. If the target function needs some parameters known at the time the listener is created, you can use a lambda
to bind that value. If the target doesn't need parameters, you don't need the intermediate lambda
. In your case the the problem is that you created a lambda
that just returns the method you want. Minimally it should call the method. But since it doesn't need an additional parameter the lambda isn't needed at all.
self.btnUpdateList.clicked.connect(operationsOnFiles.updateList)
This will expose the next bug in your code, updateList
needs a self (def updateList(self):
. And then calling super's __init__
is really strange.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments