Python Forum

Full Version: Help a programming Noob out please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys. What I'm trying to achieve is to output the text for the text string generator out to a text box on my GUI.
Im at my wits end with this haha. I would like the 'Generate' button to generate another password. As it stands. When you run the app. It outputs the generated password to the shell.
import random
import string

# get random string password with letters, digits, and symbols
def get_random_password_string(length):
    password_characters = string.ascii_letters + string.digits + string.punctuation
    password = ''.join(random.choice(password_characters) for i in range(length))
    print("Random Password:", password)
get_random_password_string(8)
from tkinter import *


window=Tk()               


b1=Button(text="Generate")
b1.grid(row=2,column=3)
def redirector(inputStr):
    textbox.insert(INSERT, inputStr) 
title_text=StringVar()
e3=Entry(window, textvariable="Author_text")
e3.grid(row=2, column=0)


l1=Label(window, text="Author: Sebz Technologies")
l1.grid (row=1, column=0)


l1=Label(window, text="Title: Password Generator")
l1.grid (row=0, column=0)



sys.stdout.write = redirector #whenever sys.stdout.write is called, redirector is called.

window.mainloop()
Your Button instance should have a 'command= ' parameter to call the get_random_password... function.

Paul