Working in module Tkinter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Working in module Tkinter

I have a 3 buttons and 1 function. How to add string from field 'text' of button to argument of function? Example: from tkinter import * def my_f(text_button): my_label.set("{} button".format(text_button)) b1 = Button(root, text="First", command=my_f) b2 = Button(root, text="Second", command=my_f) b3 = Button(root, text="Third", command=my_f) ...

15th Apr 2020, 3:16 PM
Александр Васильев
Александр Васильев - avatar
1 Answer
+ 2
I find solution: b1 = Button(root, text="First", command=lambda i="First": my_f(i)) Thanks
16th Apr 2020, 1:36 PM
Александр Васильев
Александр Васильев - avatar