So I was trying to build a project that packs random passwords. there is only two things left. I want the password to be replaced with new one when the button is clicked again. Then I want the password to be on the window not in the terminal. If some one can tell me what functions I need to finish the project and I don't mind if you have any other notes about the project.
I'll put the code bellow. ⬇
from tkinter import *
import random
import string
# recourses&def
string.digits
string.ascii_letters
abc = random.choice(string.ascii_letters)
num = random.choice(string.digits)
pun = random.choice(string.punctuation)
abc2 = random.choice(string.ascii_letters)
num2 = random.choice(string.digits)
pun2 = random.choice(string.punctuation)
abc3 = random.choice(string.ascii_letters)
num3 = random.choice(string.digits)
pun3 = random.choice(string.punctuation)
abc4 = random.choice(string.ascii_letters)
num4 = random.choice(string.digits)
pun4 = random.choice(string.punctuation)
password = abc+num+pun+abc2+" "+num2+pun2+abc3+num3+" "+pun3+abc4+num4+pun4
def myclick():
print(password)
# window
window = Tk()
window.title("Random Passwords")
# the label
label = Label(window, text=" Welcome To Random Passwords")
label.config(font=("Ink Free", 50, "bold"))
label.config(fg="#fc0331")
label.config(bg="#03fce7")
label.pack()
# button
theButton = Button(window, text="Click here!",
padx=20, pady=5, command=myclick)
theButton.pack()
# mainloop
window.mainloop()
the best way of generating a random string of a particular length is
import string
import random
def genPass(len_):#here at len argument, it should be the len of password
printable = string.printable
pas = ""
for i in range(len_):
pas+=random.choice(printable)
return pas
and then make one more label and in your myfuc
function
def myfunc(pas):
label_name.config(text=pas)
and then create a lambda myfu = lambda:myfunc(getPass(10))
and pass myfu variable as command for the button. And yeah instead of getPass(10)
you can replace 10 with any number you want or even ask if from user itself