Python Forum
PySimpleGUI FilesBrowse enable event to update value in combo
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PySimpleGUI FilesBrowse enable event to update value in combo
#1
Photo 
Hi All,

I wanted to update combo value dynamically, when browse file.The executed procedure as below:

1)click Browse button, select what you want file.
2)Combo control in GUI update item automatically.

The problem is how to enable FileBrowse event.

Any comment will highly appreciate!!

import PySimpleGUI as psg
import pandas as pd
import os


working_directory = os.getcwd()

TestItem=[]

def read_file(csv_path):

    df=pd.read_csv(csv_path,header=1).drop([0,1])
    allitems=df.columns.tolist()
    for item in allitems:
        if item.startswith(tuple(['DUT','Ref'])):
          TestItem.append(item)
    return TestItem

psg.theme('SandyBeach')
# define layout
layout = [

    [sg.Text(""),sg.Text('Selected File')],
    [sg.Text(""),sg.InputText(key="-FILE_PATH-",size=(120, 20)),
     sg.FilesBrowse(initial_folder=working_directory,file_types=[("CSV Files","*.csv")],enable_events=True,key='-sel-')],
    [sg.Combo(TestItem,key='-newitem-')],
    [sg.Text("",size=(1,0)),sg.OK('Check Master',key='-OK-'),sg.Exit(size=(5,0))]]

window=psg.Window('Update Combo', layout)

while True:
    event,value=window.read()
    if event in (sg.WIN_CLOSED,'Exit'):
        break
    elif event=='-sel-':
        csv_add = value["-FILE_PATH-"]
        Item = read_file(csv_add)
        window['-newitem-'].update(Item)
    elif event=='-OK-':
        sg.popup("Demo")

window.close()
Reply


Messages In This Thread
PySimpleGUI FilesBrowse enable event to update value in combo - by SamLiu - Mar-13-2023, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PysimpleGUI window update dynamically SamLiu 6 4,242 Apr-05-2023, 02:32 PM
Last Post: SamLiu
Exclamation Update Point Coordinates from Mouse Event in a Plot Jguillerm 2 1,367 Jan-10-2023, 07:53 AM
Last Post: Jguillerm
  How to update the list of a combo box in a QTableView panoss 10 6,452 Feb-05-2022, 03:24 PM
Last Post: panoss
  PySimpleGUI Try Except jamesaarr 1 2,020 Nov-18-2021, 02:02 PM
Last Post: jamesaarr
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,757 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  Referencing Combo Box MC2020 6 3,058 Feb-12-2020, 10:17 PM
Last Post: woooee
  [PySimpleGUI]How to insert values that were gotten from FilesBrowse into ListBox? trigchen 0 2,920 Dec-30-2019, 06:58 AM
Last Post: trigchen
  Need help setting up a PySimpleGUI progress bar that I can maually update in script Soundtechscott 1 10,195 Jun-10-2019, 06:14 AM
Last Post: Soundtechscott
  [PySimpleGUI] update listbox not working zappfinger 2 12,186 Nov-12-2018, 08:33 PM
Last Post: zappfinger
  Need help adding a sql List to a combo box PyQt5 jimmyvegas29 1 8,716 Jul-20-2018, 07:28 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020