Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter default button in a widget

this seemed easy...

I wrote a dialog widget where I put some entries, buttons etc - among which a button I'd like to activate by mouse click, but also by pressing return. I read time ago that it was just necessary to set its default option, but I think that it changed in recent versions.

Do you know how it is possible to set it ?

thanks!

like image 856
alessandro Avatar asked May 21 '12 14:05

alessandro


1 Answers

Bind a callback to the '<Return>' event to the window (often called root in Tkinter) or to the containing frame. Have the callback accept an event parameter (which you can ignore) and have it invoke() your button's callback.

root.bind('<Return>', (lambda e, b=b: b.invoke())) # b is your button
like image 170
Steven Rumbalski Avatar answered Oct 16 '22 10:10

Steven Rumbalski