# Python program to determine which # button was pressed in tkinter # Import the library tkinter import tkinter from tkinter import * # Create a GUI app app = Tk() # Create a function with one paramter, i.e., of # the text you want to show when button is clicked def which_button(button_press): # Printing the text when a button is clicked print(button_press) label1 = tkinter.Label(font=('Arial', 12), bg="green", fg="black",text=" ") label1.grid(row=1, column=2) def key(event): app.event_generate('', warp=True, x=50, y=50) def motion(event): print('motion {}, {}'.format(event.x, event.y)) # Creating and displaying of button b1 b1 = Button(app, text="Apple", activebackground='blue', activeforeground='yellow', command=key(): which_button(m), bg="green", fg="black") b1.grid(row=0, column=1, padx=10, pady=10) # Creating and displaying of button b2 b2 = Button(app, text="Banana", command=lambda m="It is a banana": which_button(m)) b2.grid(row=0, column=2, padx=10, pady=10) # Make the infinite loop for displaying the app app.mainloop()