2

Is there a way to either choose one file in a folder or multiple files in a folder or just a folder (and then process all the files inside it) with PySimpleGUI? So far I've made something like this:

import PySimpleGUI as sg 
layout = [[sg.Text("Select files or folder:", sg.Input(key='-IN1-'),sg.FilesBrowse('Select')],
          [sg.Button("Ok"),sg.Button("Cancel")]]
window = sg.Window("Test_window", layout)
...

But with this code I can only choose one or multiple files in a folder, and cannot choose a folder. I want a way to choose either one file, multiple files or a folder.

Bruno Fonseca
  • 93
  • 1
  • 1
  • 9
  • There's no element/widget provide such function. You may build yourself popup to show all files/directories by using `sg.Listbox` or `sg.Table` to select both. – Jason Yang Feb 24 '21 at 15:35

1 Answers1

3

You can select a folder, but not both a folder or files. Here is how to select a folder:

left_col = [[sg.Text('Folder'), sg.In(size=(25,1), enable_events=True ,key='-FOLDER-'), sg.FolderBrowse()]]
layout = [[sg.Column(left_col, element_justification='c')]    
window = sg.Window('Multiple Format Image Viewer', layout,resizable=True)
     
while True:
    event, values = window.read()
    if event in (sg.WIN_CLOSED, 'Exit'):
        break
    if event == '-FOLDER-':
        folder = values['-FOLDER-']  

This may not the best suggestion, but you could have two buttons [Files] [Folder] and let them select one or the other, would that work?

nycynik
  • 7,371
  • 8
  • 62
  • 87