is there a way of in a loop automatically setting different commands to different buttons as they are created (automatically created via loops)

or

is there a way of setting custom names to the buttons while they arecreated in a loop

i want "buttonName" to be different and known for each button???

e.g.

buttonName = Button(mainGUI, text = 'example', height = 3, width = 10, command = '''I want to add my own commands to each one?'''.place(x = 100, y = 200)

Generally you add each "button_name" instance to a list that remains after the loop exits. Note that you also want to increment/change the values for the place manager.

Partial does currying:

>>> from functools import partial
>>> 
>>> def FOO(x, y, z):
...     print((x, y, z))
... 
>>> BAR = partial(FOO, "baz", "qux")
>>> BAR(3.14)
('baz', 'qux', 3.14)

BARĀ is the same function as FOO, but it takes only one argument (the last argument). The 2 first arguments have been set to fixed values "baz" and "qux".

Edited 3 Years Ago by Gribouillis

In Tkinter command= takes only the function name, but not the call, so no arguments can be passed. The partial function allows you to do that.

This question has already been answered. Start a new discussion instead.