def submit(self):
if get1 =="":
print('please input a name')
else:
with open('users.txt',"a") as f:
f.write(get1)
f.close()
users.txt是我的文件,如下所示,namee是Entry变量, 全部用tkinter
self.namee = Entry(frame)
self.namee.grid(row=7,column=1)
这是我做的条目
get1 = self.namee.get()
这是我做的吸气剂:
self.submit = Button(frame, text="Submit",command=self.submit)
self.submit.grid(row = 26, column=0, sticky=W)
这是运行函数的按钮,启动if语句
答案 0 :(得分:1)
您在提交函数中没有获得输入字段的值。试试这个
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.