Python 3.x 我想使用TKinter将GUI中的输入保存在文本文件中。如何从条目保存到文本文件
users.txt是我的文件,下面的namee是条目变量, 都是特金特Python 3.x 我想使用TKinter将GUI中的输入保存在文本文件中。如何从条目保存到文本文件,python-3.x,user-interface,tkinter,text-files,Python 3.x,User Interface,Tkinter,Text Files,users.txt是我的文件,下面的namee是条目变量, 都是特金特 def submit(self): if get1 =="": print('please input a name') else: with open('users.txt',"a") as f: f.write(get1) f.close() 这是我写的条目 self.namee = Entry(frame) self.namee
def submit(self):
if get1 =="":
print('please input a name')
else:
with open('users.txt',"a") as f:
f.write(get1)
f.close()
这是我写的条目
self.namee = Entry(frame)
self.namee.grid(row=7,column=1)
这是我制作的getter:
get1 = self.namee.get()
这是运行函数start the if语句的按钮,在submit函数中没有输入字段的值。试试这个
self.submit = Button(frame, text="Submit",command=self.submit)
self.submit.grid(row = 26, column=0, sticky=W)
你告诉了我们你想要什么,但没有告诉我们你需要什么帮助。你的问题毫无疑问。您是否阅读了tkinter教程,是否阅读了Entry和其他小部件的文档?这个问题的答案应该很有用。我现在使用提供的链接再次编辑了代码,当我单击submit按钮时,条目显然是空的,因为我的“users.txt”文件中没有任何内容
def submit(self):
get1 = self.namee.get()
if get1 =="":
print('please input a name')
else:
with open('users.txt',"a") as f:
f.write(get1)
#f.close() # Not needed, with closes f for you.