Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้าง Password Entry Field ใน Tkinter


ภาพรวม

สมมติต้องการเพิ่ม Entry Widget รับ Password โดยทั่วไป Password แสดงด้วย "*" ทำให้ Credentials เป็น Encrypted Form สร้าง Password Field ได้ด้วย Tkinter Entry Widget

ตัวอย่างโค้ด

# 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()

ผลลัพธ์

รันโค้ดจะแสดงหน้าต่างที่มี Entry Field รับ Password และปุ่มปิดหน้าต่าง

วิธีสร้าง Password Entry Field ใน Tkinter

ป้อน Password และคลิก "Quit" เพื่อปิดหน้าต่าง