Feb-18-2021, 08:23 PM
Hello.I have 2 problems with my GUI. First of all I have 2 files ,one named GUI_password.py and the other one GUI_main.py.
Code of GUI_password.py below:
In GUI_password.py file ,in check_passcode() function ,when the passcode is correct,I want the frame_for_lock_icon to be green BUT FOR ONLY 2 SECONDS(for examle) and then I want to exit from check_passcode and from Password(...) method ,but I can't do that.
How can I fix it?
Any help will be appreciated.
Thanks.
Code of GUI_password.py below:
from tkinter import *
from tkinter import *
import tkinter.font as tkFont
from PIL import Image , ImageTk
from threading import Timer
import time
import threading
import asyncio
def delay(seconds):
t0 = time.time()
i = 1
while (i <= 1):
t1 = time.time()
if(t1 - t0 > seconds):
t0 = time.time()
i+=1
def Password(root , unlock_message , access_camera): # passcode => '12345'
activate_message = "SYSTEM ACTIVATED"
denied_message = "ACCESS DENIED"
wrong_attempts = 0
#root.configure(background = 'cyan') # background color
size_letter = tkFont.Font(family = "Helvetica" , size = 19 , weight = "bold")
message_box = Label(root , text = "PLEASE ENTER ACCESS CODE" , font = size_letter).place(x = 558 , y = 30)
user_input = StringVar() # user_+input holds a string (default value = "")
input_box = Entry(root , show = "*" , width = 6 , font = ('Verdana' , 20) )
input_box.place(x = 700 , y = 80)
lock_logo = Image.open("lock_icon.jpg")
lock_logo = lock_logo.resize( (50 , 50) , resample = 0)
lock_image = ImageTk.PhotoImage(lock_logo)
frame_for_lock_icon = LabelFrame(root , padx = 5 , pady = 5,relief = SUNKEN , bd = 0)
label_for_lock = Label(frame_for_lock_icon , image = lock_image)
label_for_lock.image = lock_image
label_for_lock.grid(row = 0 , column = 0)
frame_for_lock_icon.place(x = 725 , y = 200)
my_var = False
def check_passcode():
nonlocal wrong_attempts , my_var
size_message_attempts = tkFont.Font(size = 13)
if(input_box.get() == "12345"):
print("RIGHT")
frame_for_lock_icon = LabelFrame(root , padx = 5 , pady = 5,relief = SUNKEN , bd = 0)
label_for_lock = Label(frame_for_lock_icon , image = lock_image)
frame_for_lock_icon.configure(background = "green")
frame_for_lock_icon.place(x = 725 , y = 200)
label_for_lock.image = lock_image
label_for_lock.grid(row = 0 , column = 0)
entry_box = Entry(root , show = "*" , width = 6 , font = ('Verdana' , 20) , state = DISABLED).place(x = 700 , y = 80)
button_ok = Button(root , text = "OK" , width = 7 , pady = 8 , command = check_passcode , state = DISABLED).place(x = 655 , y = 140)
button_cancel = Button(root , text = "CANCEL" , width = 7 , pady = 8 , command = root.quit , state = DISABLED).place(x = 770 , y = 140)
#root.after(3000 , None)
#frame_for_lock_icon.after_cancel(root)
#entry_box.destroy()
#button_ok.destroy()
#button_cancel.destroy()
my_var = True
elif(input_box.get() != ""):
blink_icon()
Label(root , text = "(" + str(5 - wrong_attempts) + ")" , font = size_message_attempts).place(x = 585 , y = 145)
wrong_attempts += 1
print("WRONG")
input_box.delete(0 , END)
if(wrong_attempts == 6):
print("6 wrong attempts were given")
Entry(root , show = "*" , width = 6 , font = ('Verdana' , 20) , state = DISABLED).place(x = 700 , y = 80)
Button(root , text = "OK" , width = 7 , pady = 8 , command = check_passcode , state = DISABLED).place(x = 655 , y = 140)
Button(root , text = "CANCEL" , width = 7 , pady = 8 , command = root.quit , state = DISABLED).place(x = 770 , y = 140)
exit()
if(my_var):
return True
ok_button = Button(root , text = "OK" , width = 7 , pady = 8 , command = check_passcode , borderwidth = 3).place(x = 655 , y = 140)
cancel_button = Button(root , text = "CANCEL" , width = 7 , pady = 8 , command = root.quit , borderwidth = 3).place(x = 770 , y = 140)
var = FALSE
a = 1
def blink_icon():
#do stuff
nonlocal var , a
frame_for_lock_icon = LabelFrame(root , padx = 5 , pady = 5,relief = SUNKEN , bd = 0)
label_for_lock = Label(frame_for_lock_icon , image = lock_image)
t = Timer( 0.5 , blink_icon )
t.start()
#print("Var = " + str(var))
if(a == 5):
t.cancel()
a = 1
return
else:
if(var == True):
frame_for_lock_icon.place(x = 725 , y = 200)
label_for_lock.image = lock_image
label_for_lock.grid(row = 0 , column = 0)
else:
frame_for_lock_icon.configure(background = "red")
frame_for_lock_icon.place(x = 725 , y = 200)
label_for_lock.image = lock_image
label_for_lock.grid(row = 0 , column = 0)
var = not var
a+=1Code of GUI_main.py below:from tkinter import *
from GUI_password import Password
root = Tk()
root.geometry("1800x1100")
root.title("Vehicle app")
access = Password(root , "unlock" , True)
if(access == True):
print("DONE PASSWORD METHOD")
root.mainloop()First of all, (if you run my code) ,you will understand what I want to say.In GUI_password.py file ,in check_passcode() function ,when the passcode is correct,I want the frame_for_lock_icon to be green BUT FOR ONLY 2 SECONDS(for examle) and then I want to exit from check_passcode and from Password(...) method ,but I can't do that.
How can I fix it?
Any help will be appreciated.
Thanks.
