0

Doubt on appJar

from appJar import gui x=1 def press(button): while(x < 4): usr = app.getEntry("Username") pwd = app.getEntry("Password") if usr == "user" and pwd == "pass": print("Access granted.", "You are now logged in !") app.infoBox("Logged in", "You are now logged in !") break elif usr != "user" and pwd != "pass": print("Access denied", "Your credentials are invalid !") app.errorBox("Error", "Your credentials are invalid !") if x==4: print("No more attempts", "try again later !") app.infoBox("no more attmpt", "try again later !") app.stop() app = gui("LOGIN WINDOW") app.setBg("white") app.setFont(18) app.addLabel("title","Login") app.setLabelBg("title","orange") app.setLabelFg("title","blue") app.addLabelEntry("Username") app.addLabelSecretEntry("Password") app.addButtons(["Log In","Cancel"],press) app.setFocus("Username") app.go() this is my code. I wanted to make a password system. but users can do attempt of password 3 times only. but I am unable to solve it.plz, help with it.

23rd Jul 2021, 6:59 PM
Gouri Shinde
Gouri Shinde - avatar
2 Réponses
+ 1
Gouri Shinde if I understand correctly then you forgot adding x +=1 if usr or pwd is wrong
23rd Jul 2021, 11:22 PM
Kirill
Kirill - avatar
+ 1
Gouri Shinde if you use a while loop on a button function the loop will be infinite, thats because the function is called only when you press the button, so all you need to do is check how much times the log in button was pressed, also you used the same function for both cancel and log in button. I also recommend using app.clearAllEntries so the user doesnt have to type everything again from appJar import gui tries = 0 def log(button): global tries usr = app.getEntry("Username") pwd = app.getEntry("Password") if usr == "user" and pwd == "pass": print("Access granted.", "You are now logged in !") app.infoBox("Logged in", "You are now logged in !") elif usr != "user" or pwd != "pass": print("Access denied", "Your credentials are invalid !") app.errorBox("Error", "Your credentials are invalid !") app.clearAllEntries(callFunction = False) tries += 1 if tries == 3: print("No more attempts", "try again later !") app.infoBox("no more attmpt", "try again later !") app.stop() def cancel(button): app.stop() app = gui("LOGIN WINDOW") app.setBg("white") app.setFont(18) app.addLabel("title","Login") app.setLabelBg("title","orange") app.setLabelFg("title","blue") app.addLabelEntry("Username") app.addLabelSecretEntry("Password") app.addButtons(["Log In", "Cancel"], [log, cancel]) app.setFocus("Username") app.go()
24th Jul 2021, 10:34 AM
Kirill
Kirill - avatar