Window closes alone with Pysimplegui and shows error

Asked

Viewed 9 times

-1

Hello, I am making a registration program that opens different other windows according to which button is clicked:

inserir a descrição da imagem aqui

By clicking open the "Register" or "Log-in" window, the window appears all right. Inside my code has a data validation, in case the user type something wrong, will open another window informing the user the error, for example:

inserir a descrição da imagem aqui

So far so good! The problem comes when I click to close the error window (the red window), in theory, it was for the error screen to close, and the registration window to remain open, but instead, all windows close and present the following error in the python console:

    event, values = janela.Read()
'AttributeError: 'tuple' object has no attribute 'Read'

So, as I do to close the red window (the window that shows the user error), but that the main registration window remains open and without giving error?

Follow the Menu code (First image):

import PySimpleGUI as sg
from WinCadastrar import Window
from WinLogin import LogIn

def Tela():

#  Layout
sg.theme('Black')
layout = [
    [sg.Button('Cadastrar-se'), sg.Text(), sg.Button('Log-in')]
]

#  Janela
janela = sg.Window('Menu', layout, size=(200,50), element_justification='center')


while True:

    #  Extrair dados da tela
    event, values= janela.Read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break

    
    #  Condições
    elif event == 'Cadastrar-se':        
        Window()
        

    elif event == 'Log-in':
        LogIn()

Tela()

Module code Registration dialog:

import PySimpleGUI as sg

def Window():

sg.theme('Black')
layout = [
    [sg.Text('E-mail              '), sg.Input(size=(25,0), key='email')],
    [sg.Text('Criar senha       '), sg.Input(size=(25,0), key='Pass')],
    [sg.Text('Confirmar senha'), sg.Input(size=(25,0), key='checkPass')],
    [sg.Text()],
    [sg.Button('Cadastrar-se')]
]

#  Rodando janela
janela = sg.Window('Cadastro', layout)


while True:

    event, values = janela.Read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break

    else:    
        #  Armazenando valores
        email = values['email']
        Pass = values['Pass']
        checkPass = values['checkPass']


        if event == 'Cadastrar-se':   

            #  Verificar se o e-mail digitado é válido.
            if '@gmail.com' not in email[-10:]:

                sg.theme('DarkRed2')
                layout = [[sg.Text('E-mail e ou senha incorretos!')]]

                janela = sg.Window('', layout).Read()

            #  Verificar o tamanho da senha
            elif len(Pass) < 8:
                sg.theme('DarkRed2')
                layout = [[sg.Text('A senha deve conter no mínimo 8 caracteres.')]]

                janela = sg.Window('', layout).Read()

            #  Verificar se as senhas correspondem
            elif Pass != checkPass:
                sg.theme('DarkRed2')
                layout = [[sg.Text('As senhas não correspondem.')]]

                janela = sg.Window('', layout).Read()

            else:
                
                with open(r'Works\Log-in\obb\bcdds.txt', 'r', encoding='utf-8') as file:
                    dados = file.read()

                    #  Verificar e-mail existente
                    if email in dados:
                        sg.theme('DarkRed2')
                        layout = [[sg.Text('E-mail já cadastrado.')]]

                        janela = sg.Window('',layout).Read()

                    else:
                        #  Caso o log-in seja sucedido
                        with open(r'Works\Log-in\obb\bcdds.txt', 'a', encoding='utf-8') as file:
                            dados = file.write(f'{email},{Pass}\n')
                            
                            sg.theme('Black')
                            layout = [[sg.Text('Cadastrado com sucesso!', text_color='LightGreen')]]

                            janela = sg.Window('', layout).Read()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.