Computer >> Computer tutorials >  >> Programming >> Python

How to create a password entry field using Tkinter?


Let us suppose we want to add an Entry widget which accepts user passwords. Generally, the passwords are displayed using “*” which yields to make the user credentials in an encrypted form.

We can create a password field using tkinter Entry widget.

Example

In this example, we have created an application window that will accept the user password and a button to close the window.

#Import the required libraries
from tkinter import *

#Create an instance of tkinter frame
win= Tk()

#Set the geometry of frame
win.geometry("600x250")

def close_win():
   win.destroy()

#Create a text label
Label(win,text="Enter the Password", font=('Helvetica',20)).pack(pady=20)

#Create Entry Widget for password
password= Entry(win,show="*",width=20)
password.pack()

#Create a button to close the window
Button(win, text="Quit", font=('Helvetica bold',
10),command=close_win).pack(pady=20)

win.mainloop()

Output

Running the above code will display a window with an entry field that accepts passwords and a button to close the window.

How to create a password entry field using Tkinter?

Now, enter the password and click the “Quit” button to close the window.