我在 Tkinter 中有一个循环:
def main():
#Global Variables
windows = []
buttons = []
labels = []
messageboxes = []
global theme
theme = 0
listboxes = []
global register
register = []
global path
path = ""
# Lotsa' Code
Tkinter.mainloop()
if __name__ == "__main__":
main()
def save_f():
global register
outFile = open('FobbySave.txt', 'wb')
pickle.dump(register, outFile)
outFile.close()
global register
#At Quit
atexit.register(save_f)
atexit 失败。但是当我尝试打印寄存器时它没有问题。当我将 save_f 放入 Tkinter 循环时,它起作用了,但 atexit 没有。那么有人可以告诉我我做错了什么吗?
附言
抱歉,第一次忘记写 atexit 了。但它在我的代码中。
编辑:原始代码在这里
import pickle
import atexit
def save_f():
global register
outFile = open('Something.txt', 'wb')
pickle.dump(register, outFile)
outFile.close()
atexit.register(save_f)