estou fazendo um formulário pelo tkinter e queria saber como eu posso salvar as informações dele caso o usuário feche a aplicação pelo X vermelho da pagina, para que depois quando ele entrar de novo não precisar repetir tudo ele já escreveu. Porem queria que ele só salvasse caso ele feche.
from tkinter import ttk
import tkinter
class jogo:
def __init__(self,root):
self.Formulario()
def Formulario (self):
self.formulario = ttk.Frame(root)
self.formulario.pack()
v= tkinter.IntVar()
ttk.Checkbutton(self.formulario
,text = "check1"
,variable = v
).pack()
lbl_entry = ttk.Label(self.formulario, text = "nome:")
lbl_entry.pack()
entry = ttk.Entry(self.formulario)
entry.pack()
lbl_entry2 = ttk.Label(self.formulario, text = "cidade:")
lbl_entry2.pack()
entry2 = ttk.Entry(self.formulario)
entry2.pack()
bt= ttk.Button(self.formulario,text = "savar", command = lambda : self.Save(entry.get(),entry2.get()))
bt.pack()
def Save(self,a,b):
print(a)
print(b)
root = tkinter.Tk()
jogo(root)
root.mainloop()