Sep-16-2020, 03:16 AM
Hi
I tried to set a password with widget Entry,
The right password is "tarek"
Only 3 attempts are allowed
the goal is :
when i enter a wrong password this text will appear in comment area :
*before the 1er attempt no text will appear
*after the 1st wrong password entry : "Try again, remaining attempts :2"
*after the 2st wrong password entry : "Try again, remaining attempts :1"
*after the 3st wrong password entry : "Acces denied, out of try" and the program will exit
when i enter the correct password, this text will appear in comment area : "Congratulation, acces autorized" and an other file that i alled "program2.py" will automatically executed.
The issues with my code are :
-this message appears even after the 2nd or the 3rd wrong password entry : "Try again, remaining attempts :2"
-I dont know how to insert a command to exit after the 3rd wrong attempt
-I dont know how to insert a command to execute the other program "program2.py" when i enter the right password
I wonder if i have to use the "WHILE function" instead of the "if function" or to use an other widget or kind of event?
Please can you help me to correct my code .
(Sorry I couldnt use python tags )
My code is the following :
___________________________________________________
I tried to set a password with widget Entry,
The right password is "tarek"
Only 3 attempts are allowed
the goal is :
when i enter a wrong password this text will appear in comment area :
*before the 1er attempt no text will appear
*after the 1st wrong password entry : "Try again, remaining attempts :2"
*after the 2st wrong password entry : "Try again, remaining attempts :1"
*after the 3st wrong password entry : "Acces denied, out of try" and the program will exit
when i enter the correct password, this text will appear in comment area : "Congratulation, acces autorized" and an other file that i alled "program2.py" will automatically executed.
The issues with my code are :
-this message appears even after the 2nd or the 3rd wrong password entry : "Try again, remaining attempts :2"
-I dont know how to insert a command to exit after the 3rd wrong attempt
-I dont know how to insert a command to execute the other program "program2.py" when i enter the right password
I wonder if i have to use the "WHILE function" instead of the "if function" or to use an other widget or kind of event?
Please can you help me to correct my code .
(Sorry I couldnt use python tags )
My code is the following :
___________________________________________________
# -*- coding: utf-8 -*- from tkinter import ttk, Entry #import tkinter as tk from tkinter import * from tkinter import filedialog import os from PIL import Image, ImageTk import sqlite3 import getpass Profile = {1:""} def authorization(event) : rightpassword="tarek" word = entrypassword.get() nb_attempt = 1 attempt_limit = 3 attempt_authorized = True if word != rightpassword : nb_attempt = nb_attempt+1 if nb_attempt <= attempt_limit: attempt_authorized = True comments = ("Try again, remaining attempts : " + str(attempt_limit +1 - nb_attempt)) entrycomment.delete(0, END) entrycomment.insert(0, comments) print(entrycomment.get()) else : attempt_authorized = False comments = ("Access denied, out of try") entrycomment.delete(0, END) entrycomment.insert(0, comments) print(entrycomment.get()) exit else: comments = "Congratulation Access authorized" entrycomment.delete(0, END) entrycomment.insert(0, comments) print(entrycomment.get()) open("D:/program2.py") root = Tk() root.title("Access Application") root.geometry("1400x480") #root.configure(bg = "#eaeaea") # Add Title1 lblTitle1 = Label(root , text = "Gestion des accès" , font = ("Arial" , 21) , bg="darkblue" , fg = "white" ) lblTitle1.place(x=50 , y=0 , width=300) # password area lbpassword = Label(root , text = "Password :" , font = ("Arial" , 21), bg="darkblue" , fg = "white" ) lbpassword.place(x=450 , y=200 , width=300) entrypassword = Entry(root, font = ("Arial" , 21)) entrypassword.bind("<Return>" , authorization) entrypassword.place(x=780 , y=200 , width=300) lbcomment = Label(root , text = "Comment :" ,font = ("Arial" , 21), bg="black" , fg = "white" ) lbcomment.place(x=180 , y=250 , width=250) entrycomment = Entry(root , font = ("Arial" , 21), bg="white" , fg = "red" ) entrycomment.place(x=450 , y=250 , width=800) root.mainloop()