Python Forum
[Tkinter] [SOLVED] Password generation UnboundLocalError exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] [SOLVED] Password generation UnboundLocalError exception
#4
Here is another example of a password generator

# Do the imports
from random import sample
import string

import tkinter as tk

# Combine upper and lower case letters with digits and special characters
# into a string
characters = string.ascii_letters + string.digits + '!@#$&*+'

# Define the function
def password_generator(passwd):
    # Return a joined string with 10 sample charcters
    # return ''.join(sample(characters, 10))
    passwd['text'] = ''.join(sample(characters, 10))

root = tk.Tk()
label = tk.Label(root, text='Password Generater', bg='steelblue', fg='white')
label['font'] = ('serif', 18, 'bold')
label.pack()

passwd = tk.Label(root, bg='antiquewhite', relief='ridge')
passwd['font'] = ('serif', 14, 'normal')
passwd.pack(expand=True, fill='x', pady=4)

button = tk.Button(root, text='Generate Password', command=lambda: password_generator(passwd))
button['font'] = ('comic sans ms', 12, 'bold')
button.pack(expand=True, fill='x')
root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: [SOLVED] Password generation UnboundLocalError exception - by menator01 - Nov-14-2022, 08:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Is it possible to automate button generation in tkinter? FirePepi 3 2,428 Apr-10-2020, 12:14 PM
Last Post: Riddle
  [WxPython] Issues with Exe generation and Packaging dependencies Ravikumar 1 2,636 Nov-23-2017, 12:53 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020