I have a PySimpleGUI table updating from a list. In that list, the first item is a website link. How can I make PySimpleGUI recognise them as clickable links within it's table? I have the following code which creates the table from a list that is updating periodically, column 1 contains websites that I would like clickable:
import PySimpleGUI as sg
def getData():
#data update code that creates a new list every x secs
return [("https://www.google.com", "Google", "10", "5445", "No"),("https://www.yahoo.com", "yahoo", "2", "333", "Yes")]
dat = getData()
headings = ["Link", "Name", "Users", "Id", "Authorized"]
sg.set_options(dpi_awareness=True)
layout = [
[sg.Table(values=dat, headings=headings, max_col_width=25,
auto_size_columns=True,
enable_events=True,
# display_row_numbers=True,
justification='right',
num_rows=20,
alternating_row_color=sg.theme_button_color()[1],
key='-TABLE-',
# selected_row_colors='red on yellow',
# enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
enable_click_events=True, # Comment out to not enable header and other clicks
)],
]
window = sg.Window('Table Element - Example 1', layout, resizable=True, finalize=True)
while True:
dat = getData() #get new data for table
event, values = window.read(timeout=1000)
if event in (sg.WIN_CLOSED, 'Exit'):
break
elif event == sg.TIMEOUT_KEY:
window['-TABLE-'].update(values=dat)
window.refresh()
window.close()
Use option
enable_click_events
to get where you clicked on the Table element.The format for the event will be:
('-TABLE-', '+CLICKED+', (row, col))
It will mean the column-0 link clicked ifrow
is notNone
, greater or equal then 0, andcol
is 0.Reduced Example Code - There's no way to change the color or underline for specific cell, so just only for clickable link.