E
E
expp2020-05-10 20:33:55
Python
expp, 2020-05-10 20:33:55

tkinter. The data is lost when the program is closed. How to fix it?

Good afternoon. I decided to write a program that could store key-value data (in my case, login:password) that the user entered or displays a value for him if he (already in another department) enters the key.
The essence of the problem is that the data is saved only for the duration of the program, that is, if you close the program, the previously entered data will be deleted. How to fix this and make "reusable" data saving? Thank you.
The code itself:

spoiler
# Import
from tkinter import *
from tkinter import messagebox

#Window settings
root = Tk()
root.resizable( width = False, height = False)
root.geometry("500x400")
root.title("Auto")
root["bg"] = "#262927"
root.iconbitmap( "D:/code/eye.ico" )

# Dict

passwords = {"login: password"}

# Function
def save ( event ):
Z = repeat.get()
O = password_repeat.get()
passwords[Z] = O
messagebox.showinfo("Успех", "Я все сохранил")

def check ( event ):
L = login.get()
if L in passwords:
messagebox.showinfo("Успех", f"Пароль: {passwords[L]}")
else:
messagebox.showerror("Нету", "Извини, такого не держим")

# Button
login_text = Label(text = "Введите данные", font = "Bahnschrift 20", fg = "#b9ffb0", bg = "#262927")

login = Entry(root,
font = "Bahnschrift 20",
bg = "#0c0d0c",
fg = "#cfcfcf",
relief = "solid",
justify = "center")

pass_text = Label(text = " ", bg = "#262927" )

enter = Button(text = "Узнать информацию",
fg = "#ccc",
bg = "#000000",
font = "Bell 20",
activeforeground = "#ccc",
activebackground = "#ffffff",
relief = "solid",

)

pass_text1 = Label(text = " ", bg = "#262927" )

repeat_text = Label(text = "Введите логин",
font = "Bahnschrift 20",
fg = "#b9ffb0",
bg = "#262927")

repeat = Entry(root,
font = "Bahnschrift 20",
bg = "#0c0d0c",
fg = "#cfcfcf",
relief = "solid",
justify = "center")

password_text = Label(text = "Введите пароль",
font = "Bahnschrift 20",
fg = "#b9ffb0",
bg = "#262927")

password_repeat = Entry(root,
font = "Bahnschrift 20",
bg = "#0c0d0c",
fg = "#cfcfcf",
relief = "solid",
justify = "center")

pass_text2 = Label(text = " ", bg = "#262927" )

password_button = Button(text = "Сохранить информацию",
fg = "#ccc",
bg = "#000000",
font = "Bell 20",
activeforeground = "#ccc",
activebackground = "#ffffff",
relief = "flat"
)

# Pack
login_text.pack()
login.pack()
pass_text.pack()
enter.pack()
pass_text1.pack()
repeat_text.pack()
repeat.pack()
password_text.pack()
password_repeat.pack()
pass_text2.pack()
password_button.pack()

# Binds
enter.bind("", check)
password_button.bind("", save)

root.mainloop()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Deleting Account, 2020-05-10
@expp

Read about ways to store data in python. In your case, you can use json as an alternative . And respect pep8 for a bit.

V
Vladimir, 2020-05-10
@vintello

and you are not afraid to publish the code of your super program, especially if it stores such important data as login and password?
5eb83faa4d2b2929118746.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question