每次我重新启动程序时,它都会显示以前附加的列表和腌制的列表。当我尝试将新数据添加到列表时,会出现问题。先前存储的数据将被删除,新数据将被腌制。我真的很困惑,并且一直在努力解决这一问题长达2天。任何帮助都将是惊人的,谢谢!
关于我的程序的背景: 我正在尝试制作一个gui,使我能够轻松保存各种类型的数据,以便以后可以使用该数据进行可视化表示。
这是我的整个程序:
import pickle
import os
os.system("clear")
import tkinter as tk
win = tk.Tk()
win.title("first gui")
#Program
#Functions
tips = []
days = []
amount_of_cars = []
weather = []
temperature = []
def add_all_stuff():
pickle1 = open("tips.txt","wb")
pickle2 = open("days.txt","wb")
pickle3 = open("cars.txt","wb")
pickle4 = open("weather.txt","wb")
pickle5 = open("temperature.txt","wb")
a1=tips_ask.get()
a2=days_ask.get()
a3=cars_ask.get()
a4=weather_ask.get()
a5=temperature_ask.get()
print(temperature_ask.get())
print(weather_ask.get())
print(cars_ask.get())
print(days_ask.get())
print(tips_ask.get())
tips.append(a1)
days.append(a2)
amount_of_cars.append(a3)
weather.append(a4)
temperature.append(a5)
print(tips)
print(days)
print(amount_of_cars)
print(weather)
print(temperature)
#pickle dumps
pickle.dump(tips,pickle1)
pickle1.close
pickle.dump(days,pickle2)
pickle2.close
pickle.dump(tips,pickle3)
pickle3.close
pickle.dump(tips,pickle4)
pickle4.close
pickle.dump(tips,pickle5)
pickle5.close
def show_lists():
pickle_in1 = open("tips.txt","rb")
tips = pickle.load(pickle_in1)
print(tips)
#labels
tk.Label(win,text = "menu").grid(row=0)
tk.Label(win,text= "Tips").grid(row=1)
tk.Label(win,text= "Day").grid(row=2)
tk.Label(win,text= "Amount of Cars").grid(row=3)
tk.Label(win,text= "Weather").grid(row=4)
tk.Label(win,text= "Temperature").grid(row=5)
#entryboxes
tips_ask = tk.Entry(win)
tips_ask.grid(row=1,column=1)
days_ask = tk.Entry(win)
days_ask.grid(row=2,column=1)
cars_ask = tk.Entry(win)
cars_ask.grid(row=3,column=1)
weather_ask = tk.Entry(win)
weather_ask.grid(row=4,column=1)
temperature_ask = tk.Entry(win)
temperature_ask.grid(row=5,column=1)
#Buttons
tk.Button(win,text="add",command = add_all_stuff).grid(row=6,column = 1)
tk.Button(win,text="View saved lists",command = show_lists).grid(row=6,column=2)
win.mainloop()