1 回答
TA贡献1852条经验 获得超7个赞
该entry1对象是该show_settings()方法的本地对象,因此它在内部不可见settings_save()
将对象移动到类中,它将可见
# import modules
from tkinter import*
from tkinter import messagebox as mb
import os.path
...
entry1 = None;
entry2 = None;
entry3 = None;
...
def show_settings():
settings=Tk()
settings.geometry('400x200')
entry1=Entry(settings)
entry2=Entry(settings)
entry3=Entry(settings)
...
save=Button(settings,text='SAVE!',command=settings_save)
save.grid(row=6, column=0, columnspan=2)
def settings_save(): #save values to a file
file = open("data.txt",'a')
file.write('\n' + str(entry1.get()) + ' \n' + str(entry2.get()) + '\n' + str(entry3.get()))
file.close()
...
w.mainloop()
添加回答
举报