From 16df165603b8495ca7b862a0577595c2d3769b55 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 8 Jul 2022 08:13:13 -0400 Subject: [PATCH] Addition of double-clicking and showing the get_liast_clicked_position function. --- ...Demo_Table_Element_Header_or_Cell_Clicks.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/DemoPrograms/Demo_Table_Element_Header_or_Cell_Clicks.py b/DemoPrograms/Demo_Table_Element_Header_or_Cell_Clicks.py index aeb43ac6..63ff1593 100644 --- a/DemoPrograms/Demo_Table_Element_Header_or_Cell_Clicks.py +++ b/DemoPrograms/Demo_Table_Element_Header_or_Cell_Clicks.py @@ -15,6 +15,7 @@ import operator This demo shows how you can use these click events to sort your table by columns + Copyright 2022 PySimpleGUI """ sg.theme('Light green 6') @@ -55,6 +56,7 @@ layout = [[sg.Table(values=data[1:][:], headings=headings + ['Extra'], max_col_w auto_size_columns=True, display_row_numbers=False, justification='right', + right_click_selects=True, num_rows=20, alternating_row_color='lightyellow', key='-TABLE-', @@ -72,23 +74,33 @@ layout = [[sg.Table(values=data[1:][:], headings=headings + ['Extra'], max_col_w # ------ Create Window ------ window = sg.Window('The Table Element', layout, - ttk_theme='clam', - resizable=True) + # ttk_theme='clam', + resizable=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT, finalize=True) + +# Add the ability to double-click a cell +window["-TABLE-"].bind('' , "+-double click-") # ------ Event Loop ------ while True: event, values = window.read() print(event, values) - if event == sg.WIN_CLOSED: + if event == sg.WIN_CLOSED or event == 'Exit': break + if event == 'Edit Me': + sg.execute_editor(__file__) + elif event == 'Version': + sg.popup_scrolled(__file__, sg.get_versions(), location=window.current_location(), keep_on_top=True, non_blocking=True) if event == 'Double': for i in range(1, len(data)): data.append(data[i]) window['-TABLE-'].update(values=data[1:][:]) elif event == 'Change Colors': window['-TABLE-'].update(row_colors=((8, 'white', 'red'), (9, 'green'))) + elif event == '-TABLE-+-double click-': + print('Last cell clicked was', window['-TABLE-'].get_last_clicked_position()) if isinstance(event, tuple): # TABLE CLICKED Event has value in format ('-TABLE=', '+CLICKED+', (row,col)) + # You can also call Table.get_last_clicked_position to get the cell clicked if event[0] == '-TABLE-': if event[2][0] == -1 and event[2][1] != -1: # Header was clicked and wasn't the "row" column col_num_clicked = event[2][1]