2 回答

TA貢獻1851條經驗 獲得超4個贊
刪除您當前的“emails.txt”。它的格式不正確,無法使以下內容正常工作。
改成save這樣。注意\n你的=*20
def save():
with open("emails.txt", "a") as f:
f.write(f'{e.get()}\n{p.get()}\n{"="*20}\n')
添加此功能
def get_emails():
try:
with open("emails.txt", "r") as f:
for i, line in enumerate(filter(lambda t: t != f'{"="*20}\n', f.readlines())):
if not i%2:
textEmail.set(f'{textEmail.get()}{line}')
else:
textPassword.set(f'{textPassword.get()}{line}')
except FileNotFoundError:
pass
在前面添加這一行roots.mainloop()
get_emails()
在旁邊:
您真的要將未加密的電子郵件和密碼信息存儲在文本文件中嗎?

TA貢獻1856條經驗 獲得超5個贊
為了使電子郵件地址出現在開頭,您必須從文件中獲取該信息。只需添加另一個打開文件(如果存在)、讀取地址并設置變量的函數textEmail
def set_email():
try:
file = open("emails.txt", "r")
emails = file.readlines()
last_address = emails[-2][:-1] # line before last line without the line break
file.close()
textEmail.set(last_address)
except:
pass ## There was no file "emails.txt"
如果在定義變量后調用此函數textEmail,您將獲得窗口加載時的地址。
添加回答
舉報