Here we will learn how to collect value entered by user in Entry Widget. get() is used to collect value from Entry Widget.
Entry_Widget_Class_Object.get()
below is the code to collect value from Entry widget on button click, GUI will look like as above image
#project to destroy window
try:
from Tkinter import *
except:
from tkinter import *
def collect_data():
data=entry.get()
print("data entered by user : ",data)
mw = Tk()
mw.geometry("500x100+50+50")
mw.title("AETies : Automation Expert Technologies")
label = Label(mw, text='to collect data from Entry Widet')
label.grid(row=1, column=1)
entry = Entry(mw, width=20)
entry.grid(row=2, column=2)
btn = Button(mw, text='collect data', command=collect_data)
btn.grid(row=2, column=3)
mw.mainloop()
#Output
data entered by user : Er M S Dandyan
To print user entered data on GUI application itself
Code :
#project to destroy window
try:
from Tkinter import *
except:
from tkinter import *
def collect_data():
data=entry.get()
var.set(data)
mw = Tk()
var=StringVar()
mw.geometry("500x200+50+50")
mw.title("AETies : Automation Expert Technologies")
label = Label(mw, text='to collect data from Entry Widet')
label.grid(row=1, column=1)
entry = Entry(mw, width=20)
entry.grid(row=2, column=2)
btn = Button(mw, text='collect data', command=collect_data)
btn.grid(row=2, column=3)
output_lbl = Label(mw, text='Data collected is')
output_lbl.grid(row=4, column=1)
message = Message(mw, textvariable=var, width=200)
message.grid(row=5, column=2)
mw.mainloop()
Comments
Post a Comment