1

I'm trying to add a file path to my application using an entry, but every time the entry returns an empty string

def command1(event):
    if entry1.get() == 'localhost' and entry2.get() == 'amine' and   entry3.get()=='aze123qsd' and entry4.get()=='GTFS':
    top = Toplevel()
    top.title("Add a file")
    top.geometry("600x300")
    text=Label(top ,text="Add the file path")
    text.place(relx=0.3 ,rely=0.3)
    entry=Entry(top)
    entry.place(relx=0.5 ,rely=0.3)
    paths=entry.get()
    entry.bind('<Return>', commnad3)
    button1 = Button(top, text="show the last window")
    button1.place(relx=0.55 ,rely=0.7)
    button2 =Button(top ,text="Use old data", command=old)
    button2.place(relx=0.3 ,rely=0.7)
1
  • 1
    entry.get() is being ran at immediately after entry is defined and not later after you have put something in entry. You need to put entry.get() into a function. Commented Jul 31, 2019 at 13:17

1 Answer 1

2

Your problem is due to creating entry at the same time you are performing get() on that entry. All you will have at that moment is an empty entry field.

You need to grab that entry information after something has been put into it.

Take this example and let me know if you have any questions.

import tkinter as tk


root = tk.Tk()


def print_entry(e):
    print(e.get())


def command1():
    top = tk.Toplevel()
    entry = tk.Entry(top)
    entry.pack()
    tk.Button(top, text="Print Entry", command=lambda: print_entry(entry)).pack()


tk.Button(root, text="TOPLEVEL", command=command1).pack()

root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.