Python Forum

Full Version: gui and yhrinker buttoms
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to python. Can't seem to get the button to run the script to generate random passwords. Using py 3.8 and windows 10
from tkinter import *
window=Tk()
lbl=Label(window, text="You can generate 5 random passwords by pressing Run", fg='red', font=("Helvetica", 10))
lbl.place(x=60, y=50)
btn=Button(window, text="Run", fg='blue', command = 'run')
btn.place(x=80, y=100)
window.title('Password Generator')
window.geometry("500x500+10+10")
def run():
    import random
    import string    
    def randomString(stringLength):
        letters = string.ascii_letters
        return ''.join(random.choice(letters) for i in range(stringLength))
        print("Random String with the combination of lowercase and uppercase letters")
        print("First Random String is ", randomString(10))
        print("second Random String is ", randomString(10))
        print("thired Random String is ", randomString(10))
        print("forth Random String is ", randomString(10))
        print("fifth Random String is ", randomString(10))
window.mainloop()
Maybe this will help.

#! /usr/bin/env python3
import tkinter as tk
import random as rnd
import string

def password():
    row = 2
    for i in range(6):
        passwd = rnd.sample(string.ascii_letters, 10)
        label = tk.Label(root)
        label['text'] = ''.join(passwd)
        label.grid(column=0, row=row+i, sticky='w', padx = 5)

root = tk.Tk()

label = tk.Label(root)
label['text'] = 'Generate 5 random passwords'
label.grid(column=0, row=0, pady=10, padx=5)

button = tk.Button(root, text='Generate Passwords', command=password)
button.grid(column=0, row=1, pady=10, padx=5, sticky='nw')

root.geometry('300x300+100+100')
root.mainloop()
Thanks so much.