我有这段代码,问题是当我完成程序并重新启动时,它不会将电子邮件保存在屏幕上,只保存在email.txt.
我怎样才能在屏幕上添加电子邮件和密码,因为即使我重新启动文件,电子邮件仍然出现在屏幕上,而不仅仅是在email.txt?
from tkinter import *
from tkinter import messagebox
import tkinter.messagebox
roots = Tk()
roots.title("Email's save")
roots.geometry("500x500")
e = Entry(roots)
e.grid(row=0, column=1)
e.focus_set()
p = Entry(roots, show="*")
p.grid(row=1, column=1)
p.focus_set()
textEmail = StringVar()
textPassword = StringVar()
def callback():
textEmail.set(textEmail.get() + e.get() + "\n")
textPassword.set(textPassword.get() + p.get() + "\n")
def cleargrid():
textEmail.set("")
textPassword.set("")
def delete():
answer = tkinter.messagebox.askquestion('Delete', 'Are you sure you want to delete this entry?')
if answer == 'yes':
cleargrid()
def save():
email_info = e.get()
password_info = p.get()
file = open("emails.txt", "a")
file.write(email_info)
file.write("\n")
file.write(password_info)
file.write("\n")
file.write("=" * 20)
file.close()
def EmailPassword():
email = Label(roots, text="Email: ", font=('Courier', 14))
email.grid(row=0, sticky=W)
passoword = Label(roots, text="Password: ", font=('Courier', 14))
passoword.grid(row=1, sticky=W)
saved_email = Label(roots, text="Saved Email", font=('Courier', 14))
saved_email.grid(row=15, column=0)
saved_password = Label(roots, text="Password", font=('Courier', 14))
saved_password.grid(row=15, column=15)
write_email = Label(roots, textvariable=textEmail, font=('Courier', 14))
write_email.grid(row=20, column=0)
write_password = Label(roots, textvariable=textPassword, font=('Courier', 14))
write_password.grid(row=20, column=15)
btn_save = Button(roots, text="Save", command= lambda:[callback(), save()])
btn_save.grid(row=10, column=2, sticky=W)
btn_del = Button(roots, text="X", fg="red", command=delete)
btn_del.grid(row=60, column=20)
roots.mainloop()
EmailPassword()
繁花不似锦
RISEBY
相关分类