Python‎ > ‎tkinter‎ > ‎

tkinter.Entry


Definition
Entry widget which allows to display simple text.

Syntax
tkinter.Entry()
Entry()

Options
Entry( background, bd, bg, borderwidth, cursor, exportselection, fg, font, foreground, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertborderwidth, insertofftime, insertontime, insertwidth, invalidcommand, invcmd, justify, relief, selectbackground, selectborderwidth, selectforeground, show, state, takefocus, textvariable, validate, validatecommand, vcmd, width, xscrollcommand )

Methods
Examples
Here are examples:
from tkinter import*

master=Tk()

e1=Entry(master, width=20)
e1.pack()

B=Button(master, text="Submit")
B.pack()

master.mainloop




Entry().get()
The Entry.get() input text verified through Button(command).
from tkinter import*

master=Tk()
master.title("Login")

def validate1():
    if  entry.get()=="pythonlake":
        label1=Label(master, text="Welcome")
        label1.grid(row=0,column=3)
        entry.destroy()
        button.destroy()
        label.destroy()
    else:
        label2=Label(master, text="You are not authorized", background="red", fg="white")
        label2.grid(row=0,column=3)

label=Label(master, text="Enter your username: ")
label.grid(row=0,column=0)
           
entry=Entry(master)
entry.grid(row=0,column=1)

button=Button(master, text="Submit",command=validate1)
button.grid(row=0,column=2)

master.mainloop()








The tkinter.Entry is used to check the string characteristics through string methods.

master=Tk()
master.title("String methods")

def cap():
    try:
        c=str.capitalize(s.get())
        s.set(c)
        
        pass

def cfold():
    try:
        c=str.casefold(s.get())
        s.set(c)
        
    except ValueError:
        pass

def ifier():
    try:
        if str.isidentifier(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass

def ipace():
    try:
        if str.isspace(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")

    except ValueError:
        pass

def iric():
    try:
       if str.isnumeric(s.get())==True:
           s.set("Yes")
       else:
           s.set("No")        
                
    except ValueError:
        pass

def ower():
    try:
        if str.islower(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")        
        
    except ValueError:
        pass

def inum():
    try:
        if str.isalnum(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")        
    except ValueError:
        pass

def imal():
    try:
        if str.isdecimal(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass

    

def igit():
    try:
        if str.isdigit(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass


def clr():
    try:
        s.set("")
        
              
    except ValueError:
        pass



entry=Entry(master, textvariable=s)
entry.grid(row=0, columnspan=4, sticky=W+E)


button_capitalize=Button(master, text="capitalize", width=10, command=cap)
button_capitalize.grid(row=2, column=0)

button_casefold=Button(master, text="casefold",width=10, command=cfold)
button_casefold.grid(row=2, column=1)

button_isidentifier=Button(master, text="isidentifier",width=10,command=ifier)
button_isidentifier.grid(row=2, column=2)


button_isspace=Button(master, text="isspace",width=10, command=ipace)
button_isspace.grid(row=3, column=0)

button_endswith=Button(master, text="endswith", width=10, command=iric)
button_endswith.grid(row=3, column=1)

button_islower=Button(master, text="islower",width=10, command=ower)
button_islower.grid(row=3, column=2)



button_isalnum=Button(master, text="isalnum",width=10, command=inum)
button_isalnum.grid(row=4, column=0)

button_isdecimal=Button(master, text="isdecimal",width=10, command=imal)
button_isdecimal.grid(row=4, column=1)

button_isdigit=Button(master, text="isdigit",width=10, command=igit)
button_isdigit.grid(row=4, column=2)

button_clear=Button(master, text="Clear", command=clr )
button_clear.grid(row=5, columnspan=3,sticky=W+E)












tkinter.Entry.Delete()
The method deleted the entered text through button option(command)
from tkinter import*

master=Tk()

def e1_delete():
    e1.delete(first=0,last=22)

e1=Entry(master, width=20)

B=Button(master, text="Submit", command=e1_delete)
B.pack()

master.mainloop






The code created Label, Entry, and button with defined parameters of row and colum in grid.
 from tkinter import*

master=Tk()
master.title("Grid Widget")

label=Label(master, text="First Name",font=10)
label.grid(row=0)
entry = Entry(master)
entry.grid(row=0, column=1)


label=Label(master, text="Last Name", font=10)
label.grid(row=1)
entry = Entry(master)
entry.grid(row=1, column=1)

button1=Button(master, text="Submit")
button1.grid(row=2, column=1)


master.mainloop()





tkinter.Entry
The method  Erase text, delete Entry, and destroy the widget() through Button(command) through  default pack() setting.
from tkinter import*

master=Tk()

def e1_delete():
    e1.delete(first=0,last=100)

def master_destroy():
     master.destroy()
    

def entry_destroy():
    e1.destroy()
    

e1=Entry(master, width=35)
e1.pack()


b_erase=Button(master, text="Erase", command=e1_delete)
b_erase.pack()

b_quit_destroy=Button(master, text="Quit", command=master_destroy)
b_quit_destroy.pack()


b_delete_text=Button(master, text="Delete Entry", command=entry_destroy)
b_delete_text.pack()


master.mainloop()


 











tkinter


Comments