-1
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 is my file, and namee as you can see below is the Entry variable, all with tkinter

self.namee = Entry(frame)
self.namee.grid(row=7,column=1)

this is the entry i have made

get1 = self.namee.get()

this is the getter i have made:

self.submit = Button(frame, text="Submit",command=self.submit)
self.submit.grid(row = 26, column=0, sticky=W)

and this is the button to run the function the start the if statement

Graham
  • 7,431
  • 18
  • 59
  • 84
Daniel G
  • 47
  • 8
  • You've told us what you want, but not what you need help with. There's no question in your question. Have you worked through a tkinter tutorial, and have you read the documentation for Entry and other widgets? – Bryan Oakley Apr 25 '17 at 14:01
  • The answers to this question should be useful http://stackoverflow.com/questions/9815063/get-contents-of-a-tkinter-entry-widget – j_4321 Apr 25 '17 at 14:30
  • i have now edited the code again using the links provided and when i click the submit button apparently the entry is empty as nothing goes into my 'users.txt' file – Daniel G Apr 25 '17 at 14:42

1 Answers1

1

You aren't getting the value of entry field inside your submit function. Try this

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.
scotty3785
  • 6,763
  • 1
  • 25
  • 35