function without argument doesnt work. but why?

osman-coskun

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)
tdelaney

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

why does params byte[] argument doesnt work?

From Dev

Why doesnt it work without overflow hidden?

From Dev

Why doesnt my scanf work in the function?

From Dev

Why EventListener remove function doesnt work with "querySelectorAll"

From Dev

Why doesnt my cartesian product function work?

From Dev

Why isupper() function doesnt work in if condition?

From Dev

Why doesnt self made slope function work

From Dev

Idk why this function doesnt work [react]

From Dev

List.pop() doesnt work as expected as a function argument

From Dev

why does my checkall function work but the uncheckall function doesnt

From Dev

why doesnt this jquery work?

From Dev

Why doesnt this code work?

From Dev

Why this Dropdown doesnt work?

From Dev

Onclick function doesnt work

From Dev

Browserify doesnt work with function?

From Dev

Eval function doesnt work

From Dev

Java function doesnt work

From Dev

nested function doesnt work

From Dev

Why doesnt ResultSet.deleteRow() work with query using Trim() function

From Dev

Why doesnt Promise.all() work with async function?

From Dev

Why does event.preventDefault() work without passing event as an argument in a callback function in some cases in jQuery?

From Dev

Why does the default argument not work in a template function?

From Dev

Why my script doesnt work?

From Dev

rowfun in Matlab: why doesnt this work?

From Dev

Why doesnt the OR logical operator( || ) work?

From Dev

Why doesnt 127.255.255.255 work as loopback

From Dev

Why doesnt this code work correctly

From Dev

why stringbuffer doesnt work in this code?

From Dev

Why doesnt my break work