Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- country=[] #empty list of countries
- populations=[] #empty list of populations.
- def function1(chosenLetter,shownCountries): #function accepts parameters
- counter=0 #starts counter from 0
- for line in shownCountries: #loops through the characters of each lines
- if((line[0]== chosenLetter)): #matches contents of converted file with letter inputted by user
- splitCountry=line.split("\t-\t") #splits each line with " - "
- country.append(splitCountry[0]) #split by countries
- populations.append(int(splitCountry[1])) #split by their correspoding populations
- for countryname in country:
- counter+=1
- print(countryname)
- print("Countries with the letter inputted by user: ",chosenLetter, "number of coutries ",counter)
- def function2(country,populations):
- for x in range(0,len(populations)):
- if (max(populations) == populations[x]):
- print("country with highest population is ",country[x], "- ", populations[x])
- def btnPress():
- if userName.get()=="admin" and password.get()=="secret":
- messagebox.showinfo("info", "Valid")
- root.destroy()
- while(True):
- chosenLetter=input("Enter only the first letter: ").upper() #allows user to type in whatever case he wants
- if chosenLetter.isalpha()==True and len(chosenLetter) == 1: #if chosenletter is alpha (alphabet) and is only 1 letter
- shownCountries=open("Countries.txt", "r") #read access from text file
- function1(chosenLetter,shownCountries) #executes function
- function2(country,populations) #executes function
- else:
- print("numbers are not allowed")
- else:
- messagebox.showinfo("info", "Invalid")
- root=Tk()
- root.minsize(width=350, height=300)
- root.wm_title("Countries Generation")
- lblMessage1 = Label(root,text="Username:", fg="black")
- lblMessage1.pack()
- userName=StringVar()
- Entry(root, textvariable=userName).pack()
- lblMessage2 = Label(root,text="Password:", fg="black")
- lblMessage2.pack()
- password=StringVar()
- Entry(root, textvariable=password).pack()
- btnLoginName=Button(root, text="Check Login..", command=btnPress)
- btnLoginName.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement