所以我要做的是用字典创建一个文件并添加一个新的值对。然后,在终止代码之后,我想使用该文件,但是该文件应使用新的值对进行更新。就像在注册某物后使用登录名并始终保存该登录名。
import pickle
import PySimpleGUI as sg
layout = [
[sg.Text("Bruuuuuuuuuuuuuuuuuuuuh")],
[sg.Button("Bruh"), sg.Button("Close")]
]
window = sg.Window("Bruuuuh window", layout)
dictionary = {
1: "one",
2: "two",
3: "three",
}
pickle_out = open("dict.pickle", "wb")
pickle.dump(dictionary, pickle_out)
pickle_out.close()
pickle_in = open("dict.pickle", "rb")
dictionary = pickle.load(pickle_in)
while True:
event, value = window.read()
if event in (None, "Bruh"):
sg.popup("Bruh window 2")
dictionary.update({"example": "example"})
sg.popup(dictionary)
elif event in (None, "Close"):
window.close()
break