Friday, 21 January 2022

Python7B- Write python GUI program to generate a random password with upper and lower case letters.

 Write python GUI program to generate a random password with upper and lower case letters.

 from tkinter import Button, Entry, Frame, Label, LabelFrame, Tk

import string

from secrets import choice

from tkinter.constants import END

UPPERCASE = list(string.ascii_uppercase)

LOWERCASE = list(string.ascii_lowercase)

 import os, random, string

from tkinter import *

 def get_random_string(max_chars=10):

    #chars = string.ascii_letters + string.digits + string.punctuation

    chars = string.ascii_letters

    random.seed = (os.urandom(1024))

    random_str = ''.join(random.choice(chars) for _ in range(max_chars))

    return random_str

  

def update_random_string():

      try:

        count_chars = int(pass_len.get())

    except ValueError:

        return

     pass_box.config(state=NORMAL)

    pass_box.delete(0, 'end')

    pass_box.insert(0, get_random_string(count_chars))

    pass_box.config(state="readonly")

  mainWindow = Tk()

 mainWindow.resizable(0, 0)

 frame = Frame(mainWindow)

 frame.pack(side=TOP, pady=10, padx=10, fill=X, expand=1)

 Label(frame, text="Password Length: ", anchor=E).grid(row=0, column=0, sticky=E)

 pass_len = Entry(frame)

pass_len.insert(0, '10')

pass_len.grid(row=0, column=1)

 btn = Button(frame, text="Generate Password")

btn['command'] = lambda: update_random_string()

btn.grid(row=0, column=2, rowspan=1, padx=10, ipadx=10)

 Label(frame, text="Generated password: ", anchor=E).grid(row=1, column=0, sticky=E)

pass_box = Entry(frame)

pass_box.grid(row=1, column=1)

 update_random_string()

 

mainWindow.mainloop()