You can create a function that takes any number of arguments like this:
def clickOrEnterSubmit(self, *args):
This is called a list of arbitrary arguments . The caller can freely pass as many arguments as he wants, and all of them will be packed into the args tuple. The "Enter" binding can be passed to its 1 event object, and the click command can take no arguments.
Here is a minimal Tkinter example:
from tkinter import * def on_click(*args): print("frob called with {} arguments".format(len(args))) root = Tk() root.bind("<Return>", on_click) b = Button(root, text="Click Me", command=on_click) b.pack() root.mainloop()
Result by pressing Enter and pressing the button:
frob called with 1 arguments frob called with 0 arguments
If you don't want to change the signature of the callback function, you can wrap the function you want to bind in the lambda expression and discard the unused variable:
from tkinter import * def on_click(): print("on_click was called!") root = Tk()
Kevin source share