The simplest way to add functionality to a button is called command binding, whereby a callback function is mentioned in the form of command = some_callback in the widget option. Note that the command option is available only for a few selected widgets.
Take a look at the following sample code:
def my_callback (): # do something when button is clicked
After defining the preceding callback, we can connect it to, say, a button with the command option referring to the callback, as follows:
tk.Button(root, text="Click me", command=my_callback)
A callback is a function memory reference ( my_callback in the preceding example) that is called by another function (which is Button in the preceding example) and that takes the first function ...