Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. from tkinter import*
  2.  
  3. country=[] #empty list of countries
  4. populations=[] #empty list of populations.
  5.  
  6. def function1(chosenLetter,shownCountries): #function accepts parameters
  7. counter=0 #starts counter from 0
  8. for line in shownCountries: #loops through the characters of each lines
  9. if((line[0]== chosenLetter)): #matches contents of converted file with letter inputted by user
  10. splitCountry=line.split("\t-\t") #splits each line with " - "
  11. country.append(splitCountry[0]) #split by countries
  12. populations.append(int(splitCountry[1])) #split by their correspoding populations
  13. for countryname in country:
  14. counter+=1
  15. print(countryname)
  16. print("Countries with the letter inputted by user: ",chosenLetter, "number of coutries ",counter)
  17.  
  18.  
  19.  
  20. def function2(country,populations):
  21. for x in range(0,len(populations)):
  22. if (max(populations) == populations[x]):
  23. print("country with highest population is ",country[x], "- ", populations[x])
  24.  
  25. def btnPress():
  26. if userName.get()=="admin" and password.get()=="secret":
  27. messagebox.showinfo("info", "Valid")
  28. root.destroy()
  29. while(True):
  30. chosenLetter=input("Enter only the first letter: ").upper() #allows user to type in whatever case he wants
  31. if chosenLetter.isalpha()==True and len(chosenLetter) == 1: #if chosenletter is alpha (alphabet) and is only 1 letter
  32. shownCountries=open("Countries.txt", "r") #read access from text file
  33. function1(chosenLetter,shownCountries) #executes function
  34. function2(country,populations) #executes function
  35. else:
  36. print("numbers are not allowed")
  37. else:
  38. messagebox.showinfo("info", "Invalid")
  39.  
  40. root=Tk()
  41. root.minsize(width=350, height=300)
  42. root.wm_title("Countries Generation")
  43.  
  44. lblMessage1 = Label(root,text="Username:", fg="black")
  45. lblMessage1.pack()
  46.  
  47. userName=StringVar()
  48. Entry(root, textvariable=userName).pack()
  49.  
  50. lblMessage2 = Label(root,text="Password:", fg="black")
  51. lblMessage2.pack()
  52.  
  53. password=StringVar()
  54. Entry(root, textvariable=password).pack()
  55.  
  56. btnLoginName=Button(root, text="Check Login..", command=btnPress)
  57. btnLoginName.pack()
  58.  
  59. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement