Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to determine which button was clicked in tkinter?


Asked by Gordon Reeves on Dec 13, 2021 FAQ



Use a different callback for each button. Tkinter does not pass any parameter to the callbacks - so, you have to pass a different callable object to each button.
Subsequently,
Tkinter Button command option sets the function or method to be called when the button is clicked. To set a function for execution on button click, define a Python function, and assign this function name to the command option of Button.
In respect to this, The container is the parent component on which you place the button. The text is the label of the button. The command specifies a callback function that will be called automatically when the button clicked. The command option associates the button’s action with a function or a method of a class.
Furthermore,
Introduction to Tkinter button widget Button widgets represent a clickable item in the applications. Typically, you use a text or an image to display the action that will be performed when clicked. Buttons can display text in a single font.
Similarly,
Make the window show up. You have already defined what a window looks like, but you also need to actually create a window. Call the Tk () function to initialize Tkinter and and return an object that will let you control the main window. Create a window of the Window class that is attached to that object.