jeudi 8 juin 2017

Tkinter skips over part of the code detailing the reaction to an input - Python

I am creating a program that judges the strength of passwords. Part of the code is supposed to check whether a password has any numbers. However, when I enter a password, it completely neglects the code detailing what to print as the output if there are no numbers, and instead returns with: 'this is too short.'

from tkinter import *

import re

def pass_Type():
  strength = pass_Type  #Applies pass_Type to the entire program

def value():
  value


def click():
    entered_text = entry.get()
    if entered_text in pass_Type:
        strength = pass_Type[entered_text]
        output.delete(0.0, END)
        output.insert(END, strength)
         #Click function
    elif len(entered_text) < 9:
        output.delete(0.0, END)
        output.insert(END, 'This is too short')
    elif pass_Type and len(entered_text) < 9:
       output.delete(0.0, END)
       output.insert(END, strength)
    elif value(entered_text):                              }
        if not any(c.isdigit() for c in value):            }
          output.delete(0.0, END)                          }
          output.insert(END, 'Incorporate some numbers')   } #The problematic area
    elif value(entered_text) and len(entered_text)  < 9:   }
        if not any(c.isdigit() for c in value):            }
          output.delete(0.0, END)
          output.insert(END, 'Try to incorporate some numbers and increase the length of your password')
    else:
        output.delete(0.0, END)
        output.insert(END, "This password is acceptable!") #When the password is ok

Password = Tk()
Password.title('Password tester') 

label = Label(Password, text="Password:")
label.grid(row=0, column=0, sticky=W)    #Entry label

entry = Entry(width=20, bg='light blue')
entry.grid(row=1, column=0, sticky=W)     #Entry box

Button(Password, text='SUBMIT',width=5, command=click).grid(row=2,column=0, sticky=W)  #Button

label = Label(Password, text='Strength:')
label.grid(row=4, column=0, sticky=W)          #Output label

output = Text(Password, width=75, height=6, wrap=WORD, background='light blue')
output.grid(row=5, column=0, columnspan=2, sticky=W)                              #Output box 

pass_Type = {
  'Password': 'This is a very predicatable password. You should incorporate numbers',
  'password': 'This is a very predicatable password. You should incorporate numbers and capital letters',  #Common password glossary 
  '12345': 'Try and incorporate some letters',
  'qwerty': 'Try to jumble up your letters so the password is not so predictable.'
  }

Password.mainloop()

When I attempt to test the code by itself by entering over 9 characters, it rejects the code with the following error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "", line 1549, in __call__
    return self.func(*args)
  File "", line 25, in click
    elif value(entered_text):
TypeError: value() takes 0 positional arguments but 1 was given

How can I make the program not skip over the aspect, and use the alternative output that I have programmed? And if incorporating numbers was the only problem, how can I fix the error?

Aucun commentaire:

Enregistrer un commentaire