-1

I am making a program that provides you with a random password in Tkinter and allows you to save the info in a .txt file but when I click the 'save info' button it saves the password but not the username and website name.

Here is the code:

import tkinter as tk 
import random

window = tk.Tk()

window.title("generator")
window.geometry("250x120")


one = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
two = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
three = ['1','2','3','4','5','6','7','8','9','0']
four = ['~','@','!','#','$','%','^','&','*','(',')','-','_','=','+',':',';',',','.','<','>','/','?']
five = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
six = ['1','2','3','4','5','6','7','8','9','0']
seven = ['~','@','!','#','$','%','^','&','*','(',')','-','_','=','+',':',';',',','.','<','>','/','?']
eight = ['~','@','!','#','$','%','^','&','*','(',')','-','_','=','+',':',';',',','.','<','>','/','?']
nine = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
ten = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

a = one[random.randint(0, 25)]
b = two[random.randint(0, 25)]
c = three[random.randint(0, 9)]
d = four[random.randint(0, 22)]
e = five[random.randint(0, 25)]
f = six[random.randint(0, 9)]
g = seven[random.randint(0, 22)]
h = eight[random.randint(0, 22)]
i = nine[random.randint(0, 25)]
j = ten[random.randint(0, 25)]

x = a+b+c+d+e+f+g+h+i+j


Generate = tk.Label(text="Here is your randomly generated password:")
Generate.grid(column=3, row=3)

UserName = tk.StringVar()
WebSite = tk.StringVar()

passw = tk.Label(text=x)
passw.grid(column=3, row=4)

username = tk.Entry(window, textvariable=UserName)
username.grid(column=3, row=5)

website = tk.Entry(window, textvariable=WebSite)
website.grid(column=3, row=6)

def storeinfo():
    logininfo = open("LoginInfo.txt", "a")
    logininfo.write("\nPassword: "+x+" Username: "+UserName.get()+" Website: "+WebSite.get())

save = tk.Button(text="Save Info", command=storeinfo())
save.grid(column=3, row=7)

window.mainloop()

Here is the information that is in the .txt file:

Password: lV6_u4+=Wy Username:  Website: 

As you can see, it does not send the username and website name that I entered in the entry field while the program was running.

I think that there must be a problem with the .get() function.

Thanks

ilke444
  • 2,641
  • 1
  • 17
  • 31
snookso
  • 377
  • 3
  • 16
  • Please reduce and enhance this into the expected [MRE](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. – Prune Apr 13 '20 at 06:11

1 Answers1

0

Problem is you storeinfo() is not getting called

save = tk.Button(text="Save Info", command=storeinfo)

You don't need to mention '()' in command

Sachin Patel
  • 499
  • 2
  • 12