How to save a .py file avoiding save_as command

Viewed 26

is there any chance to save a .py file without the "save as" pop up si showed up? In the simple GUI I've created, the first file saving is by the button Save As with the filename taken form the text in the first input field. Once the file is saved further modification should be catch by the button Save, with the same filename, and without any pop up window is displayed.

'''import PySimpleGUI as sg
import os

script_path = os.path.dirname(__file__)
sg.theme('DarkTeal9')      

layout_1 = [[sg.InputText("", key='-FILE-', font='Arial 9', size=(10,1)),
             sg.InputText("", key='-INPUT-', font='Arial 9', size=(10,1))]]
layout_2 = [[sg.Button ("Save As")]]
layout_3 = [[sg.Button('Save')]]

layout = [
          [sg.Column(layout_1, key='-LAY1-')],
          [sg.Column(layout_2, key='-SAVE_AS-'), sg.Column(layout_3, key='-SAVE-', visible=False),
           sg.Button ("Load"), sg.Button('Exit'),],
          ]
window = sg.Window("", layout, finalize = True)
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
        window.close()

    elif event == 'Save As':
        d = window['-FILE-'].get()
        filename = sg.popup_get_file('', save_as=True, no_window=True, file_types=(("Python Files", "*.py"), ("All Files", "*.*")), initial_folder=script_path, default_path = d)
        window.SaveToDisk(filename)
        window['-SAVE_AS-'].update(visible=False)
        window['-SAVE-'].update(visible=True)
    if event == 'Save':
        d = window['-FILE-'].get()
        filename = sg.popup_get_file('', save_as=True, no_window=True, file_types=(("Python Files", "*.py"), ("All Files", "*.*")), initial_folder=script_path, default_path = d)
        window.SaveToDisk(filename)
        window['-SAVE_AS-'].update(visible=False)
        window['-SAVE-'].update(visible=True)                                                       
    if event == 'Load':
        file_name = sg.popup_get_file('Load', no_window=True)
        window.LoadFromDisk(file_name)

window.close()'''
0 Answers
Related