def create_buttons(self, choices, default_choice): unique_choices = ut.uniquify_list_of_strings(choices) # Create buttons dictionary and Tkinter widgets buttons = dict() i_hack = 0 for row, (button_text, unique_button_text) in enumerate(zip(choices, unique_choices)): this_button = dict() this_button['original_text'] = button_text this_button['clean_text'], this_button['hotkey'], hotkey_position = ut.parse_hotkey(button_text) this_button['widget'] = tk.Button( self.buttonsFrame, takefocus=1, text=this_button['clean_text'], underline=hotkey_position) fn = lambda text=button_text, row=row, column=0: self.button_pressed(text, (row, column)) this_button['widget'].configure(command=fn) this_button['widget'].grid(row=0, column=i_hack, padx='1m', pady='1m', ipadx='2m', ipady='1m') self.buttonsFrame.columnconfigure(i_hack, weight=10) i_hack += 1 buttons[unique_button_text] = this_button self._buttons = buttons if default_choice in buttons: buttons[default_choice]['widget'].focus_force() # Bind hotkeys for hk in [button['hotkey'] for button in buttons.values() if button['hotkey']]: self.boxRoot.bind_all(hk, lambda e: self.hotkey_pressed(e), add=True)