Reputation: 79
i have a program which start by asking user his code so user will type code in Entry and click button or click enter in keyboard i made two similar function with different inputs to deal with this
b1 = Button(root,text='login',command = Login_click)
b1.pack()
b1.bind('<Return>',Login_bind)
def Login_click(self):
do some thing
def Login_bind(self,event):
do something
and it works very fine but is there any way to make only one function deal with clicked and enter key
Upvotes: 0
Views: 87
Reputation: 3432
You can simply define a function with event=None
as a default value so that it is optional and then use the same function for both.
b1 = Button(root,text='login',command = Login_click_and_bind)
b1.pack()
b1.bind('<Return>',Login_click_and_bind)
def Login_click_and_bind(self,event=None):
do something
Upvotes: 3