Python Forum
gui and yhrinker buttoms
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gui and yhrinker buttoms
#1
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()
Reply
#2
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()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Thanks so much.
Reply


Forum Jump:

User Panel Messages

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