0

First of all, PySimpleGUI is magnificent!!

How to save the last selected file in sg.filebrowser so that the next time I run the script, this file will be the default value in default_text from sg.InputText?

Today I have this:

import PySimpleGUI as sg

layout = [  
            [sg.Text('Selecione o Arquivo Executável na Pasta de Instalação               '), sg.InputText(default_text='' key='EXE_SPED'), sg.FileBrowse(button_text='Selecione')],
            [sg.Text('Selecione a Pasta Com os Arquivos .REC e .TXT                                '), sg.InputText(key='PASTA_ARQUI'), sg.FolderBrowse(button_text='Selecione')],
            [                                   sg.Button('OK'), sg.Button('CANCELAR')]]

Window = sg.Window('Print Folder  --  Versão 1.0', layout=layout)

while True:
    event, values = Window.read()

    if event in (None, 'CANCELAR'): # if user closes window or clicks cancel
        break
    if event == 'OK':
       print(Pvalues['EXE_SPED'])

Imagine that I selected the file C: \ Users \ Felipe \ Downloads \ Output.txt, clicked ok, the program was executed and then closed the window. So I opened the program again and will it be like this:

import PySimpleGUI as sg

layout = [  
            [sg.Text('Selecione o Arquivo Executável na Pasta de Instalação               '), sg.InputText(default_text='C: \ Users \ Felipe \ Downloads \ Output.txt' key='EXE_SPED'), sg.FileBrowse(button_text='Selecione')],
            [sg.Text('Selecione a Pasta Com os Arquivos .REC e .TXT                                '), sg.InputText(key='PASTA_ARQUI'), sg.FolderBrowse(button_text='Selecione')],
            [                                   sg.Button('OK'), sg.Button('CANCELAR')]]

Window = sg.Window('Print Folder  --  Versão 1.0', layout=layout)

while True:
    event, values = Window.read()

    if event in (None, 'CANCELAR'): # if user closes window or clicks cancel
        break
    if event == 'OK':
       print(values['EXE_SPED'])

Is there a way to do this without having to save the value in another file (like a txt for example)?

  • No, from my opinion you can not get variable value after closing the window. you have to store selected path to the any txt file. – Bhargav Desai May 29 '20 at 12:43
  • I thought maybe it could because the sg.folderbrowse method, when the window closes and I open a new program goes directly to the last folder I selected. – felipe souza Jun 01 '20 at 14:40

0 Answers0