(Oct-03-2023, 05:48 PM)ranjansanyal2007 Wrote: [ -> ] (Oct-03-2023, 05:05 PM)deanhystad Wrote: [ -> ]Guess you need to figure out why.
This is the code you had:
for result in results:
table_rows.append(list(result))
This worked, but items kept getting added on to the table instead of the table being reset to show the new items.
This didn't work:
table_rows = result
I think result was a typo, and I meant "results".
But results is probably not what we want either, because results contains multiple result, and result needed to be converted to a list to work. So somehow you need to reset table_rows to be empty, then call your for loop to add on the new rows.
rt
As the result coming as tuple, I had to convert it to a list and it worked with comprehension.
Also the table I am taking the -TABLE- from the event and it is working as expected.
Quote:I have made some success, but still struggling to create a button, which can refresh the table and clear. I have created the "Clear" button. Sharing the code below.
import dbconnect
import PySimpleGUI as PG
def outbound_ops():
PG.theme("LightBlue3")
label_TPID = PG.Text("ISA RCV ID: ")
ib_TPID = PG.InputText(key="TPID", tooltip="Enter TP ISA ID", size=30)
label_TPQUAL = PG.Text("ISA RCV QUAL: ")
ib_TPQUAL = PG.InputText(key="TPQUAL", tooltip="Enter TP ISA Qualifier", size=20)
label_sndq = PG.Text("ISA SND QUAL: ")
ib_sndq = PG.InputText(key="SNDQUAL", tooltip="Enter Sender Qualifier", size=20)
label_TPNN = PG.Text("TP NICKNAME: ")
ib_TPNN = PG.InputText(key="TPNN", tooltip="Enter TP NickName", size=30)
label_TPINTID = PG.Text("TP INTPID: ")
ib_TPINTID = PG.InputText(key="TPINTPID", tooltip="Enter INTPID", size=30)
label_MAP = PG.Text("MAP NAME: ")
ib_MAP = PG.InputText(key="MAP", tooltip="Enter MAP NAME", size=30)
label_ISASND = PG.Text("ISA SENDER ID: ")
ib_ISASND = PG.InputText(key="ISASND", tooltip="Enter ISA Sender", size=30)
label_GSRCV = PG.Text("GS RCV ID: ")
ib_GSRCV = PG.InputText(key="GSRCV", tooltip="Enter GS Receiver", size=30)
label_gssnd = PG.Text("GS SND ID: ")
ib_gssnd = PG.InputText(key="GSSND", tooltip="Enter GS Sender", size=30)
label_gsver = PG.Text("GS VERS: ")
ib_gsver = PG.InputText(key="GSVER", tooltip="Enter GS Version", size=30)
label_isaver = PG.Text("ISA VERS: ")
ib_isaver = PG.InputText(key="ISAVER", tooltip="Enter ISA Version", size=30)
label_desc = PG.Text("DESCRIPTION: ")
ib_desc = PG.InputText(key="DESC", tooltip="Enter Description: NickName_X12", size=30)
add_button = PG.Button("Add")
view_button = PG.Button("View")
delete_button = PG.Button("Delete")
update_button = PG.Button("Update")
clear_button = PG.Button("Clear")
col1 = PG.Column([[label_TPID], [label_TPNN], [label_MAP], [label_GSRCV]])
col2 = PG.Column([[ib_TPID, ], [ib_TPNN], [ib_MAP], [ib_GSRCV]])
col3 = PG.Column([[label_TPQUAL], [label_TPINTID], [label_ISASND], [label_sndq]])
col4 = PG.Column([[ib_TPQUAL], [ib_TPINTID], [ib_ISASND], [ib_sndq]])
col5 = PG.Column([[label_isaver], [label_gssnd], [label_gsver], [label_desc]])
col6 = PG.Column([[ib_isaver], [ib_gssnd], [ib_gsver], [ib_desc]])
table_toprow = ["NICKNAME", "INTPID", "ISA RCV ID", "ISA RCV QUAL", "ISA SND QUAL",
"GS VERS", "DESCRIPTION", "GS VER", "GS RCV ID", "ISA SND ID",
"GS SND ID", "MAP"]
table_rows = []
view_table = PG.Table(values=table_rows,
headings=table_toprow, max_col_width=25,
auto_size_columns=True,
display_row_numbers=False,
alternating_row_color='lightblue',
justification='center',
key='-TABLE-',
selected_row_colors='white on blue',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True
)
window = PG.Window('Outbound Operations', layout=[[col1, col2, col3, col4, col5, col6],
[view_button, add_button, update_button,
delete_button, clear_button],
[view_table]], resizable=True)
while True:
event, values = window.read()
print(event)
print(values)
if event in (PG.WIN_CLOSED, "Exit"):
break
elif event == "View":
try:
if values["TPNN"] != "":
get_query = (f"SELECT * FROM CODELIST_XREF_ITEM A, CODELIST_XREF_VERS B "
f"WHERE A.LIST_NAME=B.LIST_NAME "
f"and A.LIST_VERSION=B.DEFAULT_VERSION "
f"and A.LIST_NAME= 'TST_CDLST_OB_FF_EDI_LKUP' "
f"and SENDER_ITEM like '%{values['TPNN']}%'")
results = dbconnect.dbconn_func(get_query)
table_rows = [list(result[4:16]) for result in results]
elif values["TPID"] != "":
get_query = (f"SELECT * FROM CODELIST_XREF_ITEM A, CODELIST_XREF_VERS B "
f"WHERE A.LIST_NAME=B.LIST_NAME "
f"and A.LIST_VERSION=B.DEFAULT_VERSION "
f"and A.LIST_NAME= TST_CDLST_OB_FF_EDI_LKUP' "
f"and TEXT1 like '%{values['TPID']}%'")
results = dbconnect.dbconn_func(get_query)
table_rows = [list(result[4:16]) for result in results]
window['-TABLE-'].update(values=table_rows)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='')
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
add_button.update(disabled=True)
update_button.update(disabled=True)
delete_button.update(disabled=True)
except NameError:
PG.popup("Enter Any Value")
elif event == "Add":
if values["TPID"] != "" and values["TPQUAL"] != "":
ins_query = (f"INSERT INTO "
f"newdb.tpinfo_outbound"
f"(`tpisarcvid`,`tpisarcvqual`,`tpnickname`,`tpgsid`,"
f"`tpinternalid`,`map_name`,`tpisasenderid`) "
f"VALUES('{values['TPID']}','{values['TPQUAL']}',"
f"'{values['TPNN']}','{values['GSRCV']}',"
f"'{values['TPINTPID']}','{values['MAP']}',{values['ISASND']})")
dbconnect.dbconn_func(ins_query)
PG.popup_quick("Value Added")
window['-TABLE-'].update(values=table_rows, select_rows=None,)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='')
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
elif values["TPID"] == "":
PG.popup("ISA ID Can't be BLank")
elif values["TPNN"] == "":
PG.popup("Nickname Can't be Blank")
elif event == "Update":
if values["TPID"] != "" and values["TPQUAL"] != "":
sel_index = values["-TABLE-"][0]
print(sel_index)
print("Update")
elif values["TPID"] == "":
PG.popup("ISA ID Can't be BLank")
elif values["TPNN"] == "":
PG.popup("Nickname Can't be Blank")
elif event == '-TABLE-':
tb_index = values['-TABLE-'][0]
window['TPID'].update(value=table_rows[tb_index][2])
window['TPQUAL'].update(value=table_rows[tb_index][3])
window['TPNN'].update(value=table_rows[tb_index][0])
window['TPINTPID'].update(value=table_rows[tb_index][1])
window['MAP'].update(value=table_rows[tb_index][11])
window['ISASND'].update(value=table_rows[tb_index][9])
window['GSRCV'].update(value=table_rows[tb_index][8])
window['SNDQUAL'].update(value=table_rows[tb_index][4])
window['GSSND'].update(value=table_rows[tb_index][10])
window['GSVER'].update(value=table_rows[tb_index][5])
window['ISAVER'].update(value=table_rows[tb_index][7])
window['DESC'].update(value=table_rows[tb_index][6])
update_button.update(disabled=False)
delete_button.update(disabled=False)
window['TPNN'].update(disabled=True)
elif event == "Clear":
window['-TABLE-'].update(values='', select_rows=None)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='', disabled=False)
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
update_button.update(disabled=True)
delete_button.update(disabled=True)
add_button.update(disabled=False)
window.close()