Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- #Login GUI
- window = Tk()
- window.title("Countries Generation")
- window.geometry("400x300")
- window.configure(bg="#cccccc")
- username = "admin"
- password = "secret"
- def callback():
- if (user == username) and (passw == password):
- message.configure(text = "Valid Logged in.")
- else:
- message.configure(text = "Username and password don't match. \nPlease try again.")
- title1 = Label(window, text="Log in", bg="#6491ca")
- usertitle = Label(window, text="---Username---", bg="#6491ca")
- passtitle = Label(window, text="---Password---", bg="#6491ca")
- message = Label(window, bg="#6491ca")
- user = Entry(window)
- passw = Entry(window, show='*')
- go = Button(window, text="Log in!", command = callback, bg="#3e3365")
- title1.pack()
- usertitle.pack()
- user.pack()
- passtitle.pack()
- passw.pack()
- go.pack()
- message.pack()
- window.mainloop()
- #Lists
- countryList1 = []
- #function 1
- def readCountries(letterChosen,fh):
- counter = 0
- countryList2 = []
- populationList = []
- dataInList = fh.readlines()
- for x in range(0,len(dataInList)):
- data = dataInList[x]
- data = data.strip("\n")
- data = data.strip()
- dataInList[x] = data
- fh.close()
- for x in range(0, len(dataInList)-1):
- Length = dataInList[x]
- dataInList2 = Length.rsplit('-',1)
- countryList1.append(dataInList2[0])
- populationList.append(dataInList2[1])
- for x in countryList1:
- if(countryList1[counter][:1] == letterChosen):
- countryList2.append(countryList1[counter][:-1])
- counter+=1
- else:
- counter+=1
- for x in range(0, len(countryList2)):
- print(countryList2[x])
- print("The total amount of countries that start with the letter", letterChosen,":",len(countryList2))
- return(populationList, countryList2)
- #function 2
- #Main
- letterChosen = str(input("Enter Only The First Letter: "))
- try:
- fh = open("Countries.txt", "r")
- except IOError:
- print("The File does not exist or an Error opening it.")
- readCountries(letterChosen,fh)
- #This allows the input to only accepts 1 letter
- if len(letterChosen) > 1:
- print ("Error! Only 1 Letter is Allowed!")
- #This allows the input to only accepts letters
- elif not re.match("^[A-Za-z]*$", letterChosen):
- print ("Error! Only letters a-z allowed!")
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement