MCPcopy Index your code
hub / github.com/geekcomputers/Python / save

Function save

Password Manager Using Tkinter/main.py:36–67  ·  view source on GitHub ↗

saves the website, email, and password to a JSON file.

()

Source from the content-addressed store, hash-verified

34
35# ---------------------------- SAVE PASSWORD ------------------------------- #
36def save():
37 """saves the website, email, and password to a JSON file."""
38 website = website_entry.get()
39 email = email_entry.get()
40 password = password_entry.get()
41 new_data = {
42 website: {
43 "email": email,
44 "password": password,
45 }
46 }
47
48 if not website or not password:
49 messagebox.showerror(title="Oops", message="Please don't leave any fields empty!")
50 return
51
52 is_ok = messagebox.askokcancel(title=website, message=f"These are the details entered: \nEmail: {email} "
53 f"\nPassword: {password} \nIs it ok to save?")
54 if is_ok:
55 try:
56 with open("data.json", "r") as data_file:
57 data = json.load(data_file)
58 except (FileNotFoundError, json.JSONDecodeError):
59 data = {}
60
61 data.update(new_data)
62
63 with open("data.json", "w") as data_file:
64 json.dump(data, data_file, indent=4)
65
66 website_entry.delete(0, tk.END)
67 password_entry.delete(0, tk.END)
68
69# ---------------------------- FIND PASSWORD ------------------------------- #
70def find_password():

Callers

nothing calls this directly

Calls 4

getMethod · 0.45
loadMethod · 0.45
updateMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected