Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

How to loop over an array and create a unique event handler for each item

$
0
0

In my application, I have a list of apps,

apps = [    App("app1", "username1", "password1", "----"),    App("app2", "username2", "password2", "----"),    App("app3", "username3", "password3", "----"),]

(App() is simply a class that contains data for each app)

Later in the code, I loop over this array to create a label widget for each app.

appLabels = []for a in apps:    lbl = ptg.Label(a.name)    def left_mouse():        showEditForm(a)    lbl.on_left_click = lambda _: left_mouse()    appLabels.append(lbl)

However, when i click on any of the labels, it always calls showEditForm() with app3. How can I create a unique event handler for each app that will call showEditForm() with the right app?


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>