It's my first try at a pysimplegui application.Before I was using tkinter a lot but interface doesn't look that pretty and modern looking.
What I want to do is to have a window with 3 button, 2 to select different files and one to launch comparison function.After selecting the file I just want to interface to display the filename.If I add a sg.Text() it displays the full filepath which I don't want to because I only need to display the filename to the user.
Here is the minimal code to reproduce what I experience :
import PySimpleGUI as sgimport os# layout = [# [sg.InputText(size=(45, 1), key="File_1", disabled=True), sg.FileBrowse(enable_events=True, key="File_path_1", target=(0, 1))],# [sg.InputText(size=(45, 1), key="File_2", disabled=True), sg.FileBrowse(enable_events=True, key="File_path_2", target=(1, 1))],# [sg.Submit()]# ]layout = [ [sg.Text('Old_file '), sg.InputText(size=(45, 1), key="File_1", disabled=True), sg.FileBrowse(enable_events=True, key="File_path_1", target=(0, 1))], [sg.Text('New_file'), sg.InputText(size=(45, 1), key="File_2", disabled=True), sg.FileBrowse(enable_events=True, key="File_path_2", target=(1, 1))], [sg.Submit()] ]window = sg.Window("File compare", layout)while True: event, values = window.read() if event is None or event == "Cancel": break elif event == "File_path_1": filepath = values.get('File_path_1') window['File_1'].update(os.path.basename(filepath)) elif event == "File_path_2": filepath = values.get('File_path_2') window['File_2'].update(os.path.basename(filepath)) elif event == 'Submit': print("hello")
Here is the picture of what I get with text-label in front of it in layout :
My question is how to make it only display the filename even with the text-label in front of the filename text cell.When I add a sg.Text() element before the sg.InputText() it shows the filepath instead of the filename like I wanted initially.I thought that the key would allow to update only some part of the UI but it doesn't work that way when a sg.Text() elem is before the InputText that I want to update with the filename and NOT the filepath.
Edit : I used PySimpleGUI-4-foss==4.60.4.1 package instead of PysimpleGUI v5.0.3Thanks Mimo for the quick answer.