Python Forum
Help a programming Noob out please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help a programming Noob out please
#1
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()
Reply
#2
Your Button instance should have a 'command= ' parameter to call the get_random_password... function.

Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

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