直接从列表框和通过搜索框选择的列需要保存
在 PySimpleGUI 屏幕以及其他元素中,我有一个输入文本(搜索框)和列值列表框。我尝试为列表框添加搜索功能时遇到问题。 我刚刚开始尝试使用 PySimpleGUI,任何帮助都会很棒:-)
预期输出: 应该能够通过列表框上的搜索框提取选定的值,并从列表框中选择这些值
下面是我尝试过的代码:
form = sg.FlexForm('File split script')
layout = [
[sg.Text('Please upload file & enter the remaining details and click "submit" button to execute the script')],
[sg.Text('Input File', size=(10, 1), auto_size_text=False, justification='left')],
[sg.InputText('Please upload either the CSV/XLSX input file'), sg.FileBrowse(key="-Input_Values-")],
[sg.Text('Output File', size=(10, 1), auto_size_text=False, justification='left')],
[sg.InputText('Please choose the output folder'), sg.FolderBrowse(key="-Output_Values-")],
[sg.Text('No of records per file'), sg.InputText(key = '-no_of_records-'), sg.Text('in multiples of 1000')],
[sg.Text(' ',size=(5, 1))],
[sg.InputText('',key = '-Search_Box-', enable_events=True),sg.Button('Merge_Search_Fields_And_Listbox_Selected_Fields')],
[sg.Text('Select the Required columns')],
[sg.Listbox(values = (),select_mode= 'multiple', size=(30, 30), key='-ListBox-', enable_events=True), sg.Button("Populate Columns"), sg.Text('Double click the button',font=('Arial', 13, 'bold')) ],
[sg.Submit(), sg.Cancel()]
]
window = form.Layout(layout)
event, values = window.read()
while True:
event, values = window.read()
print(event, values)
file_path = values[0]
if event == sg.WIN_CLOSED or event == 'Cancel':
break
if event == 'Submit':
break
if event == 'Populate Columns':
#extracts columns from selected input file - stores in
#column_names list and populates in ListBox
column_names = list(df_full_content.columns)
window.Element('-ListBox-').update(values= column_names)
# My issue is with handling search box functionality
if event == '-Search_Box-':
text = values['-Search_Box-']
if text in column_names:
search_set.add(text)
window.Element('-ListBox-').update(values=search_set)
In the PySimpleGUI screen along with other elements, I have an Input-text(Search box) and ListBox of column values. Facing an issue while I'm trying to add search functionality for List-Box.
I just started experimenting with PySimpleGUI, Any help would be great :-)
Expected Output: Should be able to pull the selected values through search box on list box and which were selected from Listbox
Below is the code which I have tried :
form = sg.FlexForm('File split script')
layout = [
[sg.Text('Please upload file & enter the remaining details and click "submit" button to execute the script')],
[sg.Text('Input File', size=(10, 1), auto_size_text=False, justification='left')],
[sg.InputText('Please upload either the CSV/XLSX input file'), sg.FileBrowse(key="-Input_Values-")],
[sg.Text('Output File', size=(10, 1), auto_size_text=False, justification='left')],
[sg.InputText('Please choose the output folder'), sg.FolderBrowse(key="-Output_Values-")],
[sg.Text('No of records per file'), sg.InputText(key = '-no_of_records-'), sg.Text('in multiples of 1000')],
[sg.Text(' ',size=(5, 1))],
[sg.InputText('',key = '-Search_Box-', enable_events=True),sg.Button('Merge_Search_Fields_And_Listbox_Selected_Fields')],
[sg.Text('Select the Required columns')],
[sg.Listbox(values = (),select_mode= 'multiple', size=(30, 30), key='-ListBox-', enable_events=True), sg.Button("Populate Columns"), sg.Text('Double click the button',font=('Arial', 13, 'bold')) ],
[sg.Submit(), sg.Cancel()]
]
window = form.Layout(layout)
event, values = window.read()
while True:
event, values = window.read()
print(event, values)
file_path = values[0]
if event == sg.WIN_CLOSED or event == 'Cancel':
break
if event == 'Submit':
break
if event == 'Populate Columns':
#extracts columns from selected input file - stores in
#column_names list and populates in ListBox
column_names = list(df_full_content.columns)
window.Element('-ListBox-').update(values= column_names)
# My issue is with handling search box functionality
if event == '-Search_Box-':
text = values['-Search_Box-']
if text in column_names:
search_set.add(text)
window.Element('-ListBox-').update(values=search_set)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里选择列
您不能在模式1中使用,然后在模式2中使用,然后使用模式1以进行以下代码。
要从模式2返回模式1,您可以单击
reset
按钮。当然,您可以通过编程代码为其设置任何规则,但不能遵循它的代码,而不是本期的问题。
Two ways here to select columns
You cannot work in Mode 1, then to Mode 2, then Mode 1 for following code.
To back to Mode 1 from Mode 2, you can click
Reset
Button.Of course, you can set any rule for it by your programming code, but not for following code for it is not the question in this issue.