tkinter bindo to a button or change the command of a bind
If your function does not use Event
passed by tkinter when a widget is bind-ed, then it is fairly simple:
def check_input(self,win,event=None):
....
....
self.but = Button(win, text="Submit", command=lambda: self.check_input(win))
....
win.bind("<enter>", lambda e: self.check_input(win,e))
Though an easier and dynamic way to always follow the buttons command is(like jasonharper said) but you cannot use e
at all, even if triggered by the given event:
win.bind("<enter>", lambda e: self.but.invoke())
An example to account for using same function with bind
and command
of a button:
from tkinter import *
root = Tk()
def func(win,e=None):
if e is not None:
print(f'Triggered by the hitting the {e.keysym} key')
else:
print('Triggered by the pressing button')
but = Button(root,text='Click me',command=lambda: func(root))
but.pack()
root.bind('<Return>',lambda e: func(root,e))
root.mainloop()
Also a good time to mention, your event is wrong, either you meant '<Return>'
(enter key) or '<Enter>'
(when you enter the bounds of a widget with cursor)