Python Forum
[Tkinter] password with Entry widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] password with Entry widget
#1
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 :



___________________________________________________
# -*- 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()
Reply


Messages In This Thread
password with Entry widget - by TAREKYANGUI - Sep-16-2020, 03:16 AM
RE: password with Entry widget - by bowlofred - Sep-16-2020, 05:34 AM
RE: password with Entry widget - by TAREKYANGUI - Sep-16-2020, 08:37 PM
RE: password with Entry widget - by micseydel - Sep-17-2020, 06:01 PM
RE: password with Entry widget - by deanhystad - Sep-17-2020, 06:48 PM
RE: password with Entry widget - by TAREKYANGUI - Sep-22-2020, 01:56 PM
RE: password with Entry widget - by SnowwyWolf - Sep-23-2020, 08:53 PM
RE: password with Entry widget - by Yoriz - Sep-23-2020, 09:40 PM
RE: password with Entry widget - by TAREKYANGUI - Sep-24-2020, 05:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 921 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,624 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,112 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,323 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 7,041 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,523 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to retreive the grid location of an Entry widget kenwatts275 7 4,757 Apr-24-2020, 11:39 PM
Last Post: Larz60+
  POPUP on widget Entry taratata2020 4 3,836 Mar-10-2020, 05:04 PM
Last Post: taratata2020
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,514 Jan-23-2020, 09:00 PM
Last Post: HBH
  The coordinates of the Entry widget (canvas) when moving berckut72 8 6,102 Jan-07-2020, 09:26 AM
Last Post: berckut72

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020