I have getting confused in getting the value from the Tkinter() Entry Field. I have this kind of code...
from Tkinter import*
def valueGET(val1, val2):
from tkinter import *
import tkinter as tk
root =tk.Tk()
mystring =tk.StringVar(root)
def getvalue():
print(mystring.get())
e1 = Entry(root,textvariable = mystring,width=100,fg="blue",bd=3,selectbackground='violet').pack()
button1 = tk.Button(root,
text='Submit',
fg='White',
bg= 'dark green',height = 1, width = 10,command=getvalue).pack()
root.mainloop()
you need brackets in the print command in your function
def valueGET(val1, val2):
print val1 + " " + val2
The code call valueGET
even before submit
button is created. Then it pass the return value of the function to Button constructor as command
argument.
To register the function as callback, replace folloiwng line:
submit = Button(frame, text="Enter", width=15, command=valueGET(E1.get(), E2.get()))
with:
submit = Button(frame, text="Enter", width=15, command=lambda: valueGET(E1.get(), E2.get()))