4 Entry Widget
4 Entry Widget
The Entry Widget is a Tkinter Widget used to Enter or display a single line of text.
Syntax :
entry = tk.Entry(parent, options)
• Options of Entry widgets are bg, bd, font, fg, justify, relief, textvariable, and show.
• Show :Normally, the characters that the user types appear in the entry.
To make a .password. entry that echoes each character as an asterisk, set show=”*”.
Methods: The various methods provided by the entry widget are:
# defining a function that will get the name and password and
# print them on the screen
def submit():
name=name_var.get()
password=passw_var.get()
print("The name is : " + name)
print("The password is : " + password)
name_var.set("")
passw_var.set("")
# creating a label for
# name using widget Label
# placing the label and entry in
name_label = tk.Label(root, text = 'Username',
# the required position using grid
font=('calibre',10, 'bold'))
# method
name_label.grid(row=0,column=0)
# creating a entry for input
name_entry.grid(row=0,column=1)
# name using widget Entry
passw_label.grid(row=1,column=0)
name_entry = tk.Entry(root,textvariable = name_var,
passw_entry.grid(row=1,column=1)
font=('calibre',10,'normal'))
sub_btn.grid(row=2,column=1)
# creating a label for password
# performing an infinite loop
passw_label = tk.Label(root, text = 'Password', font =
# for the window to display
('calibre',10,'bold'))
root.mainloop()
# creating a entry for password
passw_entry=tk.Entry(root, textvariable = passw_var,
font = ('calibre',10,'normal'), show = '*')
Syntax :
entry = tk.Text(parent, options)
• Options of Text widgets are bg, bd, font, fg, height, width, cursor, padx, pady, relief,
textvariable & others such as.
• insetofftime – The time in milliseconds for which the cursor blink is off.
• insertontime – the time in milliseconds for which the cursor blink is on.
• state – defines if the widget will be responsive to mouse or keyboards movements.
• insertionwidth – defines the width of insertion character.
• yscrollcommand – to make the widget vertically scrollable.
• xscrollcommand – to make the widget horizontally scrollable.
Methods: The various methods provided by the entry widget are:
Syntax :
msg = tk.Message(parent, options)
Options of Message widgets are bg, bd, font, fg, height, width, cursor, padx, pady, relief,
textvariable etc.
Syntax :
messagebox.Function_Name(title, message [, options])
• Function_Name: This parameter is used to represents an appropriate message box function.
• title: This parameter is a string which is shown as a title of a message box.
• message: This parameter is the string to be displayed as a message on the message box.
Function_Name: There are functions or methods available in the messagebox widget.
messagebox.showinfo("showinfo", "Information")
messagebox.showwarning("showwarning", "Warning")
messagebox.showerror("showerror", "Error")
root.mainloop()
Output After clicking “Click me”
Python Code
def onClick():
tkinter.messagebox.showinfo("Welcome to GFG.", "Hi I'm your message")
button.pack(side='bottom')
root.mainloop()