mardi 12 septembre 2017

Tkinter cbox doesn't change var value

So, essentially what is going on is I made a password manager that had a password generation part to it, I moved it to a windowed Tkinter program for ease of use. I got everything down except for the check box, so at first when the function was called it would give me the error that alphabet had empty length so I set alphabet equal to the list with special characters. After that I tried them with while loops, same result. (this whole code is a function inside the program that only gets ran when a button is pressed) I know I could probably fix this issue with the init but I was hoping if anyone knew an easier way without rewriting too much.

alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*_-+=/.,?><;:"
pw_length = int(pw_lengthh.get())
if special_characters_cbox == True:
    alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*_-+=/.,?><;:"
if special_characters_cbox == False:
    alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

randompassword = ""

for i in range(pw_length):
    next_index = random.randrange(len(alphabet))
    randompassword = randompassword + alphabet[next_index]

print(randompassword)

Aucun commentaire:

Enregistrer un commentaire