Get data from Entry widget In tkinter by R4R Team

The Entry widget in Tkinter is used to accept single-line text strings from a user.
-Entry widget accept all type of type of input like string, alphabet, number and special character.
-StringVar() and IntVar() are used to declared a string and integer variable.


Syntax-

e=Entry(window,option=value)
data=e.get()
// Here get() function return the text which is enter in Entry widget from the user side


program-



from tkinter import *
#create a window screen
win=Tk()

def getdata():
t=e.get()
l.config(text=t)


#show text on screen
l=Label(win,text="Starting",bg="green",fg="white")
l.place(x=140,y=100)

#Entry field at user side
e=Entry(win)
e.place(x=140,y=140)

#Create button
b=Button(win,text="Change",bg="white",command=getdata)
b.place(x=160,y=180)

#hold the screen
win.mainloop()


output-




-In this program, we firstly create a window screen that works as a platform for other widget, then we create a Label,Button along with the Entry field.
-Here e.place(x,y) place a Entry widget at (140, 140) coordinates.
-In above Entry widget is empty,

Then Enter value in Entry widget and change the Label by getdata() method which are called by the Given Button:





Call getdata() function by clicking on the button then:-



Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!