I'm trying to do my first project with tkinter: it's a gui password generator (I had already done a non-gui passwd generator with python so I'm sure the code to generate it is okay) but I'm having trouble in making the user's input an integer and I keep getting this error:
ValueError: invalid literal for int() with base 10: ''
Here's the code:
import tkinter as tk
import random
root = tk.Tk()
canvas = tk.Canvas(root, width=600, height=350)
canvas.grid()
#Labels
label1 = tk.Label(root, text = "How many characters?")
label1.place(x = 30, y = 50)
label2 = tk.Label(root, text = "How many passwords?")
label2.place(x = 30, y = 100)
#Entry box
box1 = tk.Entry(width = 20)
box1.place(x = 200, y = 50)
box2 = tk.Entry(width = 20)
box2.place(x = 200, y = 100)
answer = tk.Label(root, text = "")
answer.place(x = 260, y = 200)
pass_lenght = int(box1.get())
num_pass = int(box2.get())
def password_generator():
characters = "abcdefghilmopqrstuvzxwjkyèàòìùABCDEFGHILMNOPQRSTUVZWJKYX1234567890!£$%&/()=?^*§ç°:_;€"
for x in range(0, pass_lenght):
empty_password = ""
for x in range(0, num_pass):
real_password = random.choice(caratteri)
empty_password = empty_password + real_password
print("Here's your password: ", empty_password)
#Button
button = tk.Button(root, text = "Commit", command = password_generator())
button.place(x = 260, y = 150)
root.mainloop()