I have created a simple application where you can enter a word and press a button, and each time you press the button, an image and 2 labels are packed onto the screen, 1 label containing the words you have typed. I want to make it so that if you close the application and reopen it, the images and labels you have placed by pressing the button are still there. How could this be done?
from tkinter import *
import pickle
import calendar
from tkcalendar import *
import calendar
from tkcalendar import *
from datetime import datetime
from datetime import date
from time import strftime
from datetime import timedelta, datetime, date
from ttkthemes import ThemedTk, THEMES
import pickle
self = Tk()
self.title('Storing data')
self.geometry("850x800")
x = 200
y = 250
c = 460
d = 290
e = 325
f = 355
g = 390
h = 420
i = 460
j = 490
LARGE_FONT= ("Verdana", 24)
SMALL_FONT=("Verdana", 12)
def get_text(file):
with open(file, "r") as MyFile:
return MyFile.read()
def edit_text(file, text, img_dir):
with open(file, "w") as MyFile:
MyFile.write(text + "\n" + "apple.png")
def step(self):
my_progress['value']+= 5
def display():
global x , y , c , d , e , f , g, h, i, j
box_image = PhotoImage(file='apple.png')
panel2 = Label(self, image=box_image, bg='#f7f6f6')
panel2.image = box_image
panel2.place(x=x, y=y)
x=x
y = y+260
#assessment name
n = Label(self, text="", bg="#e0f6fc", font=60)
n.configure(text=assessment_name.get())
n.pack()
#due date
d = Label(self, text="Due:", bg="#e0f6fc", font=SMALL_FONT)
d.pack()
#cal date
c= Label(self, text="", bg="#e0f6fc", font=SMALL_FONT)
c.pack()
button = Button(self, text="place", command=display)
button.pack()
save = Button(self, text="save", command=edit_text)
save.pack()
open_button =Button(self, text="open", command=get_text)
open_button.pack()
edit_text("textfile.txt", "label contents", "apple.png")
assessment_name = Entry(self)
assessment_name.place(relx=0.5, y=220, anchor='center')
global cal2
cal2 = Calendar(self, background="#e0f6fc", disabledbackground="white", bordercolor="light blue", headersbackground="light blue", normalbackground="#e0f6fc", foreground="black", normalforeground='black', headersforeground='white', selectmode="day", year=2021, month=8, day=9)
cal2.place(relx=0.5, y=400, anchor='center')
due_date = Button(self, text="Submit")
due_date.place(relx=0.5, y=510, anchor='center')
self.mainloop()