Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. #Login GUI
  4. window = Tk()
  5. window.title("Countries Generation")
  6. window.geometry("400x300")
  7. window.configure(bg="#cccccc")
  8.  
  9. username = "admin"
  10. password = "secret"
  11.  
  12. def callback():
  13. if (user == username) and (passw == password):
  14. message.configure(text = "Valid Logged in.")
  15. else:
  16. message.configure(text = "Username and password don't match. \nPlease try again.")
  17.  
  18. title1 = Label(window, text="Log in", bg="#6491ca")
  19. usertitle = Label(window, text="---Username---", bg="#6491ca")
  20. passtitle = Label(window, text="---Password---", bg="#6491ca")
  21. message = Label(window, bg="#6491ca")
  22.  
  23. user = Entry(window)
  24. passw = Entry(window, show='*')
  25.  
  26. go = Button(window, text="Log in!", command = callback, bg="#3e3365")
  27.  
  28. title1.pack()
  29. usertitle.pack()
  30. user.pack()
  31. passtitle.pack()
  32. passw.pack()
  33. go.pack()
  34. message.pack()
  35.  
  36. window.mainloop()
  37.  
  38. #Lists
  39. countryList1 = []
  40.  
  41. #function 1
  42. def readCountries(letterChosen,fh):
  43. counter = 0
  44. countryList2 = []
  45. populationList = []
  46. dataInList = fh.readlines()
  47. for x in range(0,len(dataInList)):
  48. data = dataInList[x]
  49. data = data.strip("\n")
  50. data = data.strip()
  51. dataInList[x] = data
  52. fh.close()
  53. for x in range(0, len(dataInList)-1):
  54. Length = dataInList[x]
  55. dataInList2 = Length.rsplit('-',1)
  56. countryList1.append(dataInList2[0])
  57. populationList.append(dataInList2[1])
  58. for x in countryList1:
  59. if(countryList1[counter][:1] == letterChosen):
  60. countryList2.append(countryList1[counter][:-1])
  61. counter+=1
  62. else:
  63. counter+=1
  64. for x in range(0, len(countryList2)):
  65. print(countryList2[x])
  66. print("The total amount of countries that start with the letter", letterChosen,":",len(countryList2))
  67. return(populationList, countryList2)
  68.  
  69. #function 2
  70.  
  71. #Main
  72. letterChosen = str(input("Enter Only The First Letter: "))
  73.  
  74. try:
  75. fh = open("Countries.txt", "r")
  76. except IOError:
  77. print("The File does not exist or an Error opening it.")
  78.  
  79.  
  80.  
  81. readCountries(letterChosen,fh)
  82.  
  83. #This allows the input to only accepts 1 letter
  84. if len(letterChosen) > 1:
  85. print ("Error! Only 1 Letter is Allowed!")
  86.  
  87. #This allows the input to only accepts letters
  88. elif not re.match("^[A-Za-z]*$", letterChosen):
  89. print ("Error! Only letters a-z allowed!")
  90.  
  91. print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement