From 3fc648209c34525b0d3770e54343055213357665 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sat, 3 Nov 2018 23:20:50 -0400 Subject: [PATCH] Table double click and return key supprt --- PySimpleGUI.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 5cdf145d..0771ae37 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -2452,7 +2452,7 @@ class Table(Element): def __init__(self, values, headings=None, visible_column_map=None, col_widths=None, def_col_width=10, auto_size_columns=True, max_col_width=20, select_mode=None, display_row_numbers=False, num_rows=None, font=None, justification='right', text_color=None, background_color=None, alternating_row_color=None, - size=(None, None), change_submits=False, pad=None, key=None, tooltip=None): + size=(None, None), change_submits=False, bind_return_key=False, pad=None, key=None, tooltip=None): ''' Table Element :param values: @@ -2491,6 +2491,7 @@ class Table(Element): self.AlternatingRowColor = alternating_row_color self.SelectedRows = [] self.ChangeSubmits = change_submits + self.BindReturnKey = bind_return_key super().__init__(ELEM_TYPE_TABLE, text_color=text_color, background_color=background_color, font=font, size=size, pad=pad, key=key, tooltip=tooltip) @@ -2527,6 +2528,20 @@ class Table(Element): self.ParentForm.TKroot.quit() + def treeview_double_click(self, event): + selections = self.TKTreeview.selection() + self.SelectedRows = [int(x) - 1 for x in selections] + if self.BindReturnKey: + MyForm = self.ParentForm + if self.Key is not None: + self.ParentForm.LastButtonClicked = self.Key + else: + self.ParentForm.LastButtonClicked = '' + self.ParentForm.FormRemainedOpen = True + if self.ParentForm.CurrentlyRunningMainloop: + self.ParentForm.TKroot.quit() + + def __del__(self): super().__del__() @@ -4566,7 +4581,9 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): ttk.Style().configure("Treeview", foreground=element.TextColor) # scrollable_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both') treeview.bind("<>", element.treeview_selected) - + if element.BindReturnKey: + treeview.bind('', element.treeview_double_click) + treeview.bind('', element.treeview_double_click) scrollbar = tk.Scrollbar(frame) scrollbar.pack(side=tk.RIGHT, fill='y') scrollbar.config(command=treeview.yview)