I’m using Tkinter for a small Python application. It has a set of ratio buttons, a text box, and a button. Is there a way to make it so the user can simply press Enter/Return on a keyboard and run the same function the button runs? The text box stays selected even when a radio is changed, so that won’t cause any problems.
Share
You should be able to bind an event handler to either the text box widget or the whole application that will be called when the event happens. Assuming you have a function to handle the event, something along the lines of:
You can also bind a handler function at the application level by calling the
bind_all()method of any widget, e.g.:Note the key name is
ReturnnotEnter. See Key Names for a list of them all. You can also prefix the key name with a modifier likeShift-andControl-if desired.There’s a decent online reference for tkinter 8.4 here.