Python 학습- 중급 과정: 26일차, Password Manager-Tkinter

오늘은 사용자로부터 암호와 사용자 이름을 가져오는 로그인 응용 프로그램을 만들어 보겠습니다.




오늘의 애플리케이션 사양은 다음과 같습니다.



1) 프로그램에는 두 개의 항목(한 줄 텍스트 상자), 하나의 버튼, 하나의 레이블 등 네 개의 위젯이 있습니다.
2) 사용자는 첫 번째 텍스트 상자에 사용자 이름을 입력합니다. 두 번째 텍스트 상자의 비밀번호입니다. 그러나 암호는 암호화되어 있습니다(표시되지 않음).
3) 사용자가 가입 버튼을 누르면 라벨에 사용자 이름이 표시되고 비밀번호가 저장됩니다.
지금은 암호를 저장하지 않고 더미 암호 입력 기능 스텁을 만듭니다. 암호는 암호화된 형식의 파일이나 다른 방법으로 파일에 저장할 수 있습니다. Python에서 파일 처리를 다루면 됩니다. 그때까지는 storepassword() 함수가 암호와 사용자 이름을 자동으로 저장한다고 가정합니다.

항목 위젯을 암호화합니다.



비밀번호를 올바르게 입력하는 동안 다른 사람이 비밀번호를 볼 수 있기를 원하지 않습니까? 이것은 show="*" 속성을 사용하여 달성할 수 있습니다.TB1=tk.Entry(form,width = 20,show="*")
import tkinter as tk

form=tk.Tk()
form.title("Example of Entry widget")
form.geometry('400x200')

TB1=tk.Entry(form,width = 20,show="*")
TB1.pack()
def show():
    button.config(text=TB1.get())
button=tk.Button(form,text="", command=show)
button.pack()
form.mainloop()
show()



이제 어제의 프로그램을 다시 방문하고 항목 위젯을 숨깁니다.



로그인 화면 구축.



우리는 이미 프로그램의 사양을 얻었으므로 이제 빌드를 시작하겠습니다. 다음은 설명을 위해 주석 처리된 프로그램 코드입니다. 솔루션을 보기 전에 먼저 시도해 보십시오.

import tkinter as tk # import the Tkinter module

form=tk.Tk() # create the blank window.
form.title("password manager") # set the title as password manager
form.geometry('400x200') # set the default geometry of the window.

TB1=tk.Entry(form, width = 20) 
# make an entry widget with 20 spaces for the username

TB2=tk.Entry(form,show="*", width = 20) 
# entry widget for password and hide the keys whenever pressed.

# TB1 is for username, TB2 is for password
TB1.pack()
TB2.pack()
# pack the widgets into 'form'

label=tk.Label(form,text="")
# make a label to display the username

def show(): #function to be executed once the button is pressed.
    a=TB1.get() # get username
    b=TB2.get() # get password
    if(a!="" and b!=""):
     label.config(text="Welcome "+a+" to python GUI",fg="Green") # display the label
     storepassword(a,b) # store password and username
    else:
     label.config(text="Please enter a valid username and password.",fg="Red")  # blank screens

def storepassword(username, password):
    #//Some mechanism to store password//
    pass #stubbed

button=tk.Button(form,text="Sign Up", command=show) # setup the button
button.pack()
label.pack()
form.mainloop()
show()








숙제 위의 응용 프로그램을 (보지 않고) 디버그하고 테스트하십시오. 애플리케이션을 passwordmanager.pyw 파일에 저장합니다. 그리고 아래 댓글로 사진을 보내주세요.


오늘의 암호 관리자는 매우 안전합니다....하지만 내일 우리는 스파이웨어에 의해 암호를 훔치는 메커니즘을 보게 될 것입니다😈
그러니 저를 팔로우하여 업데이트를 계속 지켜봐 주세요.

좋은 웹페이지 즐겨찾기