I'm trying to get the value of an entry in tkinter!
when I print the value directly ( for example print(e2.get() ) it works well, but when I put this into a variable and then print it ( for example x = e2.get() print(x) ) it's not working!
here is the code:
import tkinter as tk
def show_entry_fields():
print("First Name: %s\n Last Name: %s" % (x, e2.get()))
master = tk.Tk()
tk.Label(master,
text="First Name").grid(row=0)
tk.Label(master,
text="Last Name").grid(row=1)
e1 = tk.Entry(master)
e2 = tk.Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
x = e1.get()
tk.Button(master,
text='Quit',
command=master.quit).grid(row=3,
column=0,
sticky=tk.W,
pady=4)
tk.Button(master,
text='Show', command=show_entry_fields).grid(row=3,
column=1,
sticky=tk.W,
pady=4)
tk.mainloop()
I need to put the entry value in a variable, how can I do it?