'Prevent PySimpleGUI InputText event from executing while element is disabled when using FocusIn bind?

My GUI has an InputText box with default text that is to be cleared upon focus; however, the InputText is disabled until a ListBox selection is made. Even if a ListBox selection has not been made and the InputText box is disabled, the default text will still be cleared if the InputText box is clicked. Is there a way to prevent this? Or to check if the InputText is disabled when clicked?

Sample Code:

import PySimpleGUI as sg

def main():
    layout = [[sg.Input("Search", s=(30,1), disabled=True, k="-SEARCH-")],
              [sg.Listbox(values=["One", "Two", "Three"], s=(30,5), k='-LIST-', enable_events=True)]]

    window = sg.Window("Test", layout, use_default_focus=False, finalize=True)
    window['-SEARCH-'].bind('<FocusIn>', '_Focus')

    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Cancel':
            break
        if event == '-LIST-':
            window['-SEARCH-'].Update(disabled=False)
        if event == '-SEARCH-' + "_Focus":
            window['-SEARCH-'].Update("")
            window.refresh()

    window.close()

if __name__ == "__main__":
    main()


Solution 1:[1]

Per Jason Yang's comment, the solution was to simply add the following to my Input declaration:

use_readonly_for_disable=False

Such that:

layout = [[sg.Input("Search", s=(30,1), disabled=True, use_readonly_for_disable=False, k="-SEARCH-")],
          [sg.Listbox(values=["One", "Two", "Three"], s=(30,5), k='-LIST-', enable_events=True)]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GriffsAccount