0

I have the following GUI and i would like to turn what i write into the "Entry" area in a variable so that I can use it for other functions.

top = Tk()    
top.geometry("450x300")   
     
Dog = Label(top, text = "Dog").place(x = 40, y = 70)  
Owner = Label(top, text = "Owner ").place(x = 40, y = 100)      

Dog_input_area = Entry(top, width = 30).place(x = 150, y = 70)     
Owner_input_area = Entry(top, width = 30).place(x = 150, y = 100)   

Submit = Button(top, text = "Submit").place(x = 40, y = 190) 
      
top.mainloop()

I think I am missing something within the Submit variable, but I am not able to understand what.

I would also like to point out that if textvariable=input("Dog")is inserted into the Button, I only have the option to insert data on the IDE, which is not really useful.

Thanks

Shold
  • 75
  • 5

2 Answers2

2

If I understood what you had asked or what you're trying to do, there's a way you can get everything that was entered into the entry field using this code:

msg_in_entry = Dog_input_area.get()  # gets whatever the user wrote

Then, you can also empty the entry field using this code:

Dog_input_area.delete(0, END)  # deletes everything in the entry field

I want you to also notice that variables in Python are supposed to be written with lower case letters. Which means that "Dog_input_area" is supposed to be called as "dog_input_area". It won't crash your program but it surely is an important thing to notice among the programmers community.

Yuval
  • 108
  • 6
2

Call a function when the button is clicked using the command parameter:

dog_name = ""
owner_name = ""

def read_entries():
    global dog_name, owner_name
    dog_name = Dog_input_area.get()
    owner_name = Owner_input_area.get()

Button(top, text="Submit", command=read_entries).place(x=40, y=190)

Then, read Tkinter: AttributeError: NoneType object has no attribute <attribute name> to understand why your Dog_input_area and Owner_input_area is currently None.

Wups
  • 2,489
  • 1
  • 6
  • 17