I am trying to create a password manager in python with tkinter. But when I try to write the account name, username and password it doesn't work. I am using a text box with StringVar to get the info from the textboxes. I don't know if the bug is in the textboxes or the writing to the file. I have the following code:
from tkinter import *
from tkinter import messagebox
loginwin = Tk()
loginwin.wm_title("Login")
loginwin.geometry("225x75")
win = Tk()
win.wm_title("Password Manger")
win.geometry("550x215")
win.withdraw()
u = StringVar()
p = StringVar()
a = StringVar()
u1 = StringVar()
p1 = StringVar()
def login():
username1 = u.get()
password1 = p.get()
if username1 == "":
if password1 == "":
messagebox.showinfo("Login", "Login Complete")
loginwin.withdraw()
win.deiconify()
else:
messagebox.showinfo("Login", "Incorrect Password or Username")
else:
messagebox.showinfo("Login", "Incorrect Password or Username")
def add():
account1 = a.get()
username2 = u1.get()
password2 = p1.get()
account1 = str(account1)
username2 = str(username2)
password2 = str(password2)
with open("passwords.txt", "w") as file:
file.write("\n" + account1 + " " + username2 + " " + password2)
Label(loginwin, text=" Username: ").grid(row=1, column=1)
Label(loginwin, text=" Password: ").grid(row=2, column=1)
Label(loginwin, text="Hint: Nothing").grid(row=3, column=2)
Label(win, text=" Account: ").grid(row=1, column=1)
Label(win, text=" Username: ").grid(row=2, column=1)
Label(win, text=" Password: ").grid(row=3, column=1)
username = Entry(loginwin, textvariable = u)
username.grid(row=1, column=2)
password = Entry(loginwin, textvariable = p, show = "*")
password.grid(row=2, column=2)
account = Entry(win, textvariable = a)
account.grid(row=1, column=2)
username1 = Entry(win, textvariable = u1)
username1.grid(row=2, column=2)
password1 = Entry(win, textvariable = p1)
password1.grid(row=3, column=2)
login = Button(loginwin, text="Login", command=login)
login.grid(row=3, column=1)
add = Button(win, text="Add", command=add)
add.grid(row=4, column=1)
loginwin.mainloop()
win.mainloop()