'How to get the Values from the Entry box in Tkinter?

def in_Vals():
    in_win = Tk()
    in_win.title("Check In Details")
    in_win.geometry("700x700")
    in_win.resizable(0,0)

    # title

    title = Label(in_win,text="Check In Details",font=("Harlow Solid Italic",30,"italic"),fg="black",bg="#fbb08c")
    title.pack(anchor="center",pady=5)

    #creating label's
    _Id_ = Label(in_win,text="Id :",font=("Times New Roman",15,"italic"),fg="black",bg="#fbb08c")
    _Name_ = Label(in_win,text="Name :",font=("Times New Roman",15,"italic"),fg="black",bg="#fbb08c")
    _Date_ = Label(in_win,text="Date :",font=("Times New Roman",15,"italic"),fg="black",bg="#fbb08c")
    _Time_ = Label(in_win,text="Time :",font=("Times New Roman",15,"italic"),fg="black",bg="#fbb08c")
    _Number_ = Label(in_win,text="Number :",font=("Times New Roman",15,"italic"),fg="black",bg="#fbb08c")
    
    
    _Id_.pack(anchor='w',padx=10,pady=20)
    _Name_.pack(anchor='w',padx=10,pady=20)
    _Date_.pack(anchor='w',padx=10,pady=20)
    _Time_.pack(anchor='w',padx=10,pady=20)
    _Number_.pack(anchor='w',padx=10,pady=20)

    # creating submit function

    def submit():
        print(f"{in_val_1}\n{in_val_2}\n{in_val_3}\n{in_val_4}\n{in_val_5}")


    # creating entries

    Id = Entry(in_win,width=25,font=("Courier",15,'bold'))
    Name = Entry(in_win,width=25,font=("Courier",15,'bold'))
    Date = Entry(in_win,width=25,font=("Courier",15,'bold'))
    Time = Entry(in_win,width=25,font=("Courier",15,'bold'))
    Number = Entry(in_win,width=25,font=("Courier",15,'bold'))

    Id.place(x=100,y=87)
    Name.place(x=100,y=157)
    Date.place(x=100,y=227)
    Time.place(x=100,y=293)
    Number.place(x=100,y=360)

    #getting values

    in_val_1 = Id.get()
    in_val_2 = Name.get()
    in_val_3 = Date.get()
    in_val_4 = Time.get()
    in_val_5 = Number.get()


    # creating submit button

    submit = Button(in_win,text="Submit",font=("Wild Latin",15,"bold"),command=submit)
    submit.place(x = 250,y=450)
    
    in_win.config(bg="#fbb08c")
    in_win.mainloop()

Here the function in_vals() is a coded to take data from the ID, Name, Date, Time, Number Entries and assign the values of The entries to the variables in_val_1 to in_val_5 ,to get the values from the entry box I have used the .get() Method. but when I try to Print the Variables that I assigned to the .get() method, it prints some white Space's.



Solution 1:[1]

The solution for the problem same as mine is

defining the values outside the the button function does not get anything.

here I have defined out side the button function

after defining it inside the button function it gives me the desired output

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JOHN ARTHUR