如何在 PySImpleGui 中确定事件类型 Table

How determine event type in PySImpleGui Table

我有一个 PySimpleGui Table。 有 2 种可能的操作(在行上):

单击设置 enable_events=True,同时选择多个项目设置 select_mode=sg.TABLE_SELECT_MODE_EXTENDED

为双击事件绑定 table 和 '<Double-Button-1>'

在 double-click 事件之前,它将是单击事件。

import PySimpleGUI as sg

headings = ['President', 'Date of Birth']
data = [
    ['Ronald Reagan', 'February 6'],
    ['Abraham Lincoln', 'February 12'],
    ['George Washington', 'February 22'],
    ['Andrew Jackson', 'March 15'],
    ['Thomas Jefferson', 'April 13'],
    ['Harry Truman', 'May 8'],
    ['John F. Kennedy', 'May 29'],
    ['George H. W. Bush', 'June 12'],
    ['George W. Bush', 'July 6'],
    ['John Quincy Adams', 'July 11'],
    ['Garrett Walker', 'July 18'],
    ['Bill Clinton', 'August 19'],
    ['Jimmy Carter', 'October 1'],
    ['John Adams', 'October 30'],
    ['Theodore Roosevelt', 'October 27'],
    ['Frank Underwood', 'November 5'],
    ['Woodrow Wilson', 'December 28'],
]

layout = [[sg.Table(data, headings=headings, enable_events=True, justification='left', key='-TABLE-')]]
window = sg.Window("Title", layout, finalize=True)
window['-TABLE-'].bind("<Double-Button-1>", " Double_Click")

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    elif event == '-TABLE-':
        print(f'Row {values[event]} selected')
    elif event == '-TABLE- Double_Click':
        print(f'Double click on {values["-TABLE-"]}')

window.close()