Alex Hawking
Alex Hawking

Reputation: 1245

TKinter Get name of button from within button

I am developing an app with tkinter and I have the following code:

tricks = ['Always Three', 'bhu']

        def trickInstructions(selectedTrick):
            print(selectedTrick)

        def menu():
            for trick in tricks:
                Button(root, text = trick, pady=1, command = lambda: trickInstructions(self.name)).pack(side=BOTTOM) 

I would like to send the name of the button to the trickInstructions() function everytime the button is clicked.

Is this possible and how?

Upvotes: 0

Views: 53

Answers (1)

acw1668
acw1668

Reputation: 47173

You can pass the text using lambda via default value of argument:

command=lambda name=trick: trickInstructions(name)

Upvotes: 1

Related Questions