-2
I’m doing a test program with Pysimplegui, but basically it asks for a user, if it’s correct it opens a new tab with the phrase: "Success, you’ve logged into your account!" , and when it was wrong open a new tab with a phrase "Incorrect password. Try again". I was programming when I needed to break the loop while
when the person closes the program. I even managed to do this in the part where asks the user, but when I was doing the incorrect password part, I realized that python was not recognizing the command if click == sg.WINDOW_CLOSED:
. So I modified the code to put one input
to see if he appeared, and if he appeared the command would be recognized. But the result is the same as the beginning:
Here’s the code (I know I wouldn’t close with it, but I just wanted it to recognize the input first)
from PySimpleGUI import PySimpleGUI as sg
from time import sleep
sg.theme("LightGreen4")
x = [
[sg.Text('Usuário'), sg.Input(key='usuario')],
[sg.Button('Entrar', key = 'entrar')]
]
janela = sg.Window('lalalala', x)
s = 's'
t = 't'
while s == 's':
while t == 't':
click, valores = janela.read()
if click == sg.WINDOW_CLOSED:
s = 't'
click = 'closed'
break
elif click == 'entrar':
if valores['usuario'] == '004848':
layout = [
[sg.Text('Sucesso! Você entrou na sua conta!')]
]
break
else:
layout = [
[sg.Text('Senha incorreta. Tente novamente.')]
]
break
if valores['usuario'] == '004848':
janela3 = sg.Window('sucesso!', layout)
while True:
click = janela3.read()
pass
elif click == 'closed':
sg.Window.close(janela)
else:
janela3 = sg.Window('senha incorreta', layout)
while True:
del(click)
click = janela3.read()
if click == sg.WINDOW_CLOSED:
input('s')
sleep(100)
I’m using Windows 10 PRO, 64bit. Please, if you have an error in the question write in the comments for me to modify it. Thank you!
Why the -2?? I only organized the code
– Heitor Tasso
Now I can’t test yet, but because you used the.Hide() window and the finalize = True?
– Artur Carneiro Barroso
When you open another window, it is good to "hide" one, until the other will be unanswered (you cannot touch it). finilize is used to prevent some errors that are described in the documentation: https://pysimplegui.readthedocs.io/en/latest/
– Heitor Tasso
thanks, you solved my problem, but when I wanted to use Sleep, what I would do?
– Artur Carneiro Barroso
It depends on the use... In Pysimplegui you can use the
hide
to hide the window and then forward you can use the team. In general nn is used a lot in these cases, it is for a very specific use– Heitor Tasso