Guest User

Untitled

a guest
Nov 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. ##
  2.  
  3. Exception in Tkinter callback
  4. Traceback (most recent call last):
  5. File "C:UsersDMECHCHAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 1699, in __call__
  6. return self.func(*args)
  7. File "C:/Users/DMECHCH/OneDrive/Courses ARA/Diploma IT Tech Support Courses/DTEC501 - Programming fundementals/Week 14 Session 1/14-3 Q1.py", line 119, in <lambda>
  8. check_btn = Button(root_window,text="Change Password",command=lambda: validate_password(pwd1, pwd2))
  9. File "C:/Users/DMECHCH/OneDrive/Courses ARA/Diploma IT Tech Support Courses/DTEC501 - Programming fundementals/Week 14 Session 1/14-3 Q1.py", line 27, in validate_password
  10. pwd_length = len(password)
  11. TypeError: object of type 'StringVar' has no len()
  12. ##
  13.  
  14. ##
  15.  
  16.  
  17. # Functions
  18.  
  19. def validate_password(first_pwd, second_pwd):
  20. """
  21. validates if password is acceptable
  22. """
  23.  
  24. min_length = 8
  25.  
  26. number_of_tests = 6
  27. test1 = 0 #Both entered passwords are identical.
  28. test2 = 0 #The password is >= 8 characters in length.
  29. test3 = 0 #if first and last chars are alpha then both must be different
  30. test4 = 0 #There are no more than 2 vowels in the password.
  31. test5 = 0 #The password has at least 1 alphabetic character
  32. #in either upper or lower case.
  33. test6 = 0 #Not all alphabetic characters are in the same
  34. #case (either all upper or all lower).
  35.  
  36. # test1
  37. if first_pwd == second_pwd:
  38. test1 = 1
  39.  
  40. password = first_pwd
  41. pwd_length = len(password)
  42.  
  43. # test2
  44. if pwd_length >= 8:
  45. test2 = 1
  46.  
  47. # test3
  48.  
  49. same = 0
  50.  
  51. if password[0].isalpha() and password[pwd_length-1].isalpha():
  52. if password[0] == password[pwd_length-1].upper():
  53. same = 1
  54. if password[0] == password[pwd_length-1].lower():
  55. same = 1
  56. if same == 0:
  57. test3 = 1
  58.  
  59. else:
  60. test3 = 1
  61.  
  62.  
  63. # test4
  64. vowels = ["a","e","i","o","u","A","E","I","O","U"]
  65. count = 0
  66. max_vowels = 2
  67. for vowel in vowels:
  68. count = count + password.count(vowel)
  69.  
  70. if count <= max_vowels:
  71. test4 = 1
  72.  
  73. alpha_chars = []
  74.  
  75. # test5
  76. for char in password:
  77. if char.isalpha():
  78. alpha_chars.append(char)
  79. test5 = 1
  80.  
  81.  
  82. # test6
  83. alpha_count = len(alpha_chars)
  84. upper_count = 0
  85. lower_count = 0
  86. for char in alpha_chars:
  87. if char == char.upper():
  88. upper_count = upper_count + 1
  89. if char == char.lower():
  90. lower_count = lower_count + 1
  91.  
  92. if alpha_count != upper_count and
  93. alpha_count != lower_count:
  94. test6 = 1
  95.  
  96. test_count = test1 + test2 + test3 + test4
  97. + test5 + test6
  98.  
  99. if test_count == number_of_tests:
  100. return True
  101.  
  102.  
  103.  
  104. return False
  105.  
  106. # Program Code
  107.  
  108. from tkinter import *
  109.  
  110. root_window = Tk()
  111.  
  112. # window title
  113. root_window.title("Title")
  114.  
  115. # window size
  116. root_window.geometry("400x200")
  117.  
  118. # label asking for password
  119. pwd_label = Label(root_window, text="Please enter your password")
  120. pwd_label.pack()
  121.  
  122. # pwd entry boxes
  123.  
  124. pwd1 = StringVar()
  125. pwd1_text = Entry(root_window,textvariable=pwd1)
  126. pwd1_text.pack()
  127.  
  128. pwd2 = StringVar()
  129. pwd2_text = Entry(root_window,textvariable=pwd2)
  130. pwd2_text.pack()
  131.  
  132. # pwd check button
  133. check_btn = Button(root_window,text="Change Password",command=lambda: validate_password(pwd1, pwd2))
  134. check_btn.pack()
  135.  
  136.  
  137.  
  138.  
  139. root_window.mainloop()
  140.  
  141. ##
  142.  
  143. password = first_pwd
  144. pwd_length = len(password)
Add Comment
Please, Sign In to add comment