0

So I want my program to be able to reset the password. The problem is that everything works just fine with the first reset process, but if you wanted to reset the password one more time it gets wicked and I can't find a mistake or solution. What the program does the first time and what it should do:

When button3 is pressed show the first frame where you have to enter you current pw. If the enter key on the keyboard is pressed and the pw is right show the second frame. There, set a new pw and by hitting enter show the third frame. Type in the same pw you used in the second frame, the pw set frame. If both pw are the same go back to the title screen.

Second+ time and the PROBLEM: button3 is pressed, it shows the first frame, but the cursor is not in the entry field like it is the first time (entry.focus_set() is in the code), BUT the cursor is in the third entry field (of the last, the pw confirm, frame) without it even being .pack()ed or .raised or anything beyond. If I click the entry of the first frame (where I actually would be at this point) and confirm it shows the second frame like it is supposed to be, but the cursor now is in the entry of the first frame which is not even active anymore because it just .pack_forget(). If I proceed to the third frame the cursor is in the entry of the second frame.

from tkinter import *
root = Tk()

pw_actual = ""
pw_first = ""

def ssc_title():
    sc_pw.pack_forget()
    sc_pw_second.pack_forget()
    sc_title.pack()

def ssc_pw_change():
    sc_title.pack_forget()
    sc_pw_testing.pack()

def ssc_pw_first():
    sc_pw_testing.pack_forget()    
    sc_pw_first.pack()

def ssc_pw_second():
    sc_pw_first.pack_forget()
    sc_pw_second.pack()
#-----------------------------------
def ev_pw_testing(event):
    pw_proof = en_pw_testing.get()
    if pw_proof == pw_actual:
        en_pw_testing.delete(0, END)
        ssc_pw_first()
    else:
        en_pw_testing.delete(0, END)

def ev_pw_first(event):
    global pw_first
    pw_first = en_pw_first.get()
    if pw_first == "":
        errormessage("Please enter a password")
    else:
        en_pw_first.delete(0, END)
        ssc_pw_second()

def ev_pw_second(event):
    global pw_first
    pw_second = en_pw_second.get()
    if pw_first == pw_second:
        write(pw_second)        
        en_pw_second.delete(0, END)
        ssc_title()
    else:
        errormessage("Passwords don't match")
        en_pw_second.delete(0, END)
#------------------
sc_pw_testing = Frame(root, bg=bgclr)
lab_pw_testing = Label(sc_pw_testing, text="Please enter the password", bg=bgclr, fg=fontclr, font=font_12).pack(ipady=10)
en_pw_testing = Entry(sc_pw_testing, show="X")
en_pw_testing.pack()
en_pw_testing.focus_set()
en_pw_testing.bind("<Return>", ev_pw_testing)

sc_pw_first = Frame(root, bg=bgclr)
lab_pw_first = Label(sc_pw_first, text="Set new password", bg=bgclr, fg=fontclr, font=font_12).pack(ipady=10)
en_pw_first = Entry(sc_pw_first, show="X")
en_pw_first.pack() 
en_pw_first.focus_set()
en_pw_first.bind("<Return>", ev_pw_first) 

sc_pw_second = Frame(root, bg=bgclr)
lab_pw_second = Label(sc_pw_second, text="Confirm password", bg=bgclr, fg=fontclr, font=font_12).pack(ipady=10) 
en_pw_second = Entry(sc_pw_second, show="X")
en_pw_second.pack()
en_pw_second.focus_set()
en_pw_second.bind("<Return>", ev_pw_second)

sc_title = Frame(root, bg=bgclr)
bttn3 = Button(sc_title, text="Password reset", bg=bgclr, fg=fontclr, font=font_12, relief=FLAT, command=ssc_pw_change).pack()

#------------

root.mainloop()

(Here I didn't include irrelevant functions etc like the errormessage toplevel funtion which justs create a window or the pickle stuff, because then it'll be too long and the issue does not seem to be laying there.)

Like I was saying - the first time changing the password works just fine. Every other time after the first time the same problem occures every time. The only way to get it to work again is to restart the program. I was trying following solutions:

  • resetting the global variables before entering the reset process again
  • resetting the global variables after switching the frame and being used
  • putting each frame (or page if you will) into a function
  • putting each frame (or page) into a class following the Switch between two frames in tkinter tutorial
  • leaving the frame/page switcing functions out and put the .pack()s and .pack_forget()s right in the pw checking (event) functions
  • instead of packing using a grid
  • using ("", lambda event: function())

Each solution worked just like the code right now, no changes at all, and the problem stays just as well.

I mean I could work around it, like disable the button so you can only reset the pw one time each session, but there is no reason why it should be like that, or even omit the entry.focus_set(), so you have to click the entry field no matter what and the problem never has a chance to occur (which is seriously annoying to click each entry field before entering characters each time).

I ran out of ideas what I could try to do differently. I feel like missing the forest for the trees. Come on guys, gimme a kick in my butt, what am I missing out here!?

Community
  • 1
  • 1
tumper
  • 1
  • 1

0 Answers0