'BUTTON NOT SUBMITING DATA

I'm creating a GUI and I had an issue. My GUI is going to interact with the users, so when the user's inputs are written they have to be saven in a variable. I created a button to do this submition, but it's not working. The problem is in the sg.Button('SubmitData', visible=False) Does anyone knows why?

This is my code:

def window():

    # Definindo o fundo da tela como preto
    sg.theme('Black') 

    # Declarando o logo da mercedes
    myImg = sg.Image(filename='logo_meca_pret.png',size=(200,200))

    # Declarando os outputs
    output = sg.Text(font=("Arial",20),key="output") 
    output2 = sg.Text(font=("Arial",20),key="output2")
    output3 = sg.Text(font=("Arial",20),key="output3")
    output4 = sg.Text(font=("Arial",20),key="output4")

    layout = [
            [myImg,sg.Text('PROGRAMA DE TREINAMENTOS',font=("Arial",60),justification="center")],
            [sg.Text("Passe o cracha no leitor: ",font=("Arial",20)),sg.InputText(size=(60),key="ID")],
            [sg.Text("Escreva seu nome:  ",font=("Arial",20),visible=False,key="NAMETEXT"),sg.InputText(size=(60),visible=False,key="NAME")],
            [sg.Text("Digite seu setor(111/112/113): ",font=("Arial",20),visible=False,key="SECTIONTEXT"),sg.Input(size=(5),visible=False,key="SECTION")],
            [sg.Button('SubmitData', visible=False)],
            [output],
            [output2],
            [output3,sg.InputText(size=(1),key="w_a",visible=False)],
            [output4],
            [sg.Text("CLIQUE NO BOTAO PARA ABRIR AS TELAS DOS TUTORIAIS",font=("Arial",30),visible=False,key="BOTAOW3"),sg.Button("W3",visible=False)],
            [sg.Button('Submit', visible=False, bind_return_key=True)]
    ]

    window = sg.Window('PROGRAMA DE TREINAMENTOS MERCEDES BENZ', layout,element_justification="center").Finalize()
    window.Maximize()

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

        if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
            break
        #print('You entered ', values[0])
        if event == 'Submit':    
            ID = values["ID"]  
            ID = ID.upper() 
            if is_registered(ID) == True:            
                name,section = current_user_data(users_df,ID)
                output.update(f"Ola, {name}, bem vindo ao programa de treinamento Mercedes Benz Brasil!\n")
                videos = videos_to_watch(section,ID)
                if is_list_empty(videos,section,ID) == True:     
                    output2.update("Nao ha novos tutoriais disponiveis.")
                    output3.update("Deseja assistir algum tutorial novamente (S/N)?") 
                    window['w_a'].update(visible = True)       
                    w_a = values["w_a"]
                    if w_a == "s" or w_a == "S":
                        # abre a tela com todos os tutoriais da pasta daquela secao
                        window2()                                             

                    if w_a == "n" or w_a == "N":                         
                        # usa esses comandos para limpar a tela, para que um novo usuario use 
                         window.find_element("ID").update("") 
                         window.find_element("output").update("")
                         window.find_element("output2").update("")
                         window.find_element("output3").update("") 
                         window.find_element("w_a").update("")
                         window['w_a'].update(visible = False) # deixa o input do w_a invisivel de novo
                         window.find_element("output4").update("")
                    
                else:
                    # se tiverem videos a serem assistidos abrir a WINDOW3
                    window["BOTAOW3"].update(visible = True)
                    window["W3"].update(visible = True)
                    if event == "W3":
                       # window3()
                       print("lalala")
                    
            else:
                window["NAMETEXT"].update(visible = True)
                window["NAME"].update(visible = True)                                
                window["SECTIONTEXT"].update(visible = True)     
                window["SECTION"].update(visible = True)
                window["SubmitData"].update(visible = True)                
                if event == 'SubmitData' :  
                    name = values["NAME"]     
                    name = name.title()      
                    section = values["SECTION"]
                    output.update(f"Ola, {name}, bem vindo ao programa de treinamento Mercedes Benz Brasil!\n")

The output that I want is:

OUTPUT IMAGE



Sources

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

Source: Stack Overflow

Solution Source