How to set data inside Entry Widget and delete once click in Entry Widget



 In this project, we will be learning how to clear default set data inside Entry Widget. 

we will be calling a function on_click during bind inside Entry space in Entry Widget, which will be clearing the default set data.

Entry_Widget_Object.bind()

when the below code is executed, we will be a getting a window as above.


#program

try:
from Tkinter import *
except:
from tkinter import *

def on_click(event):
event.widget.delete(
0, END)

mw = Tk()

mw.geometry(
"600x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")

hdng = Label(mw
, text='A simple format of REGISTRATION FORM ', fg='blue', pady=10).pack()
# ********** designing name section **********
name_l = Label(mw, text='Name :\t', ).place(x=10, y=50)
name_fn = Entry(mw
, width=22)
name_fn.place(
x=100, y=50)
name_fn.insert(
0,'first name')
name_fn.bind(
"<Button-1>", on_click)
name_ln = Entry(mw
, width=22)
name_ln.place(
x=350, y=50)
name_ln.insert(
0,'last name')
name_ln.bind(
"<Button-1>", on_click)

mainloop()


once you click on first name Entry form, default data will be cleared off automatically


just enter first name and click on last name section, again default set value will be cleared off automatically


finally 


then we can further plot a button to collect the value of the entry fields.




Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India