Skip to content
Advertisement

Tkinter Events in for loop

I am currently working on an app with tkinter, which is basically PHPMyadmin. After the login I want to display all the databases in Labels and attach an Event to them. Well it kinda worked…

Currently this code just prints out all the databases when clicked, but I want it to print just its own name. If it is possible, I don’t want to create the events. Is there a way to “customize” Events?

JavaScript

Advertisement

Answer

bind sends event with information which widget was clicked and you can get text from Label using event.widget["text"]


Minimal working example:

JavaScript

PEP 8 — Style Guide for Python Code


EDIT:

If you want to send to function other value then you can use lambda to bind function with value.

If you use lambda in loop then you need first assign this value to variable in lambda

JavaScript

Or you can assign value to label – ie. label.own_value = "..." and later get it as event.widget.own_value

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement