creates a new window to display all passwords in a table.
()
| 97 | messagebox.showerror("Incorrect Password", "The master password you entered is incorrect.") |
| 98 | |
| 99 | def show_passwords_window(): |
| 100 | """creates a new window to display all passwords in a table.""" |
| 101 | all_passwords_window = tk.Toplevel(window) |
| 102 | all_passwords_window.title("All Saved Passwords") |
| 103 | all_passwords_window.config(padx=20, pady=20) |
| 104 | |
| 105 | # a frame for the treeview and scrollbar |
| 106 | tree_frame = ttk.Frame(all_passwords_window) |
| 107 | tree_frame.grid(row=0, column=0, columnspan=2, sticky='nsew') |
| 108 | |
| 109 | # a Treeview (table) |
| 110 | cols = ('Website', 'Email', 'Password') |
| 111 | tree = ttk.Treeview(tree_frame, columns=cols, show='headings') |
| 112 | |
| 113 | # column headings and widths |
| 114 | tree.heading('Website', text='Website') |
| 115 | tree.column('Website', width=150) |
| 116 | tree.heading('Email', text='Email/Username') |
| 117 | tree.column('Email', width=200) |
| 118 | tree.heading('Password', text='Password') |
| 119 | tree.column('Password', width=200) |
| 120 | |
| 121 | tree.grid(row=0, column=0, sticky='nsew') |
| 122 | |
| 123 | # a scrollbar |
| 124 | scrollbar = ttk.Scrollbar(tree_frame, orient=tk.VERTICAL, command=tree.yview) |
| 125 | tree.configure(yscroll=scrollbar.set) |
| 126 | scrollbar.grid(row=0, column=1, sticky='ns') |
| 127 | |
| 128 | # load data from JSON file |
| 129 | try: |
| 130 | with open("data.json", "r") as data_file: |
| 131 | data = json.load(data_file) |
| 132 | |
| 133 | # insert data into the treeview |
| 134 | for website, details in data.items(): |
| 135 | tree.insert("", "end", values=(website, details['email'], details['password'])) |
| 136 | |
| 137 | except (FileNotFoundError, json.JSONDecodeError): |
| 138 | # if file not found or empty, it will just show an empty table |
| 139 | pass |
| 140 | |
| 141 | def copy_selected_info(column_index, info_type): |
| 142 | """copies the email or password of the selected row.""" |
| 143 | selected_item = tree.focus() |
| 144 | if not selected_item: |
| 145 | messagebox.showwarning("No Selection", "Please select a row from the table first.", parent=all_passwords_window) |
| 146 | return |
| 147 | |
| 148 | item_values = tree.item(selected_item, 'values') |
| 149 | info_to_copy = item_values[column_index] |
| 150 | pyperclip.copy(info_to_copy) |
| 151 | messagebox.showinfo("Copied!", f"The {info_type.lower()} for '{item_values[0]}' has been copied to your clipboard.", parent=all_passwords_window) |
| 152 | |
| 153 | # a frame for the buttons |
| 154 | button_frame = ttk.Frame(all_passwords_window) |
| 155 | button_frame.grid(row=1, column=0, columnspan=2, pady=(10,0)) |
| 156 |
no test coverage detected