forked from shivangdubey/HacktoberFest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpig_latin_translator.py
More file actions
70 lines (52 loc) · 2.65 KB
/
pig_latin_translator.py
File metadata and controls
70 lines (52 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
###############################################################################################################################
#A Pig Latin is an encrypted word in English, which is generated by doing following alterations:
#The first vowel occurring in the input word is placed at the start of the new word along with the remaining alphabets of it.
#The alphabets present before the first vowel are shifted at the end of the new word followed by “ay”.
#The objective is to conceal the words from others not familiar with the rules.
###############################################################################################################################
#IMPORTING LIBRARIES#
from tkinter import *
#Translator Function#
def pig_latin():
consonant = (' B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z', 'Y')
vowel = ('A','E','I','O','U')
pig_latin_string =''
user_sentence = var.get()
user_sentence = str(user_sentence)
words = user_sentence.split()
for user_word in words:
# getting first letter and making sure its a string and setting it to uppercase
first_letter = user_word[0]
first_letter = str(first_letter)
first_letter = first_letter.upper()
if first_letter in consonant:
length_of_word = len(user_word)
remove_first_letter = user_word[1 : length_of_word]
pig_latin = remove_first_letter + first_letter + 'ay'
pig_latin_string = pig_latin_string + ' ' + pig_latin
elif first_letter in vowel:
pig_latin = user_word + 'way'
pig_latin_string = pig_latin_string + ' ' + pig_latin
else:
pig_latin_string = 'INVALID INPUT!'
var1.set(pig_latin_string)
#Tkinter root with window title#
root = Tk()
root.title("Pig Latin Translator")
root.resizable(0, 0) #Stops window from being resized
#Creating a Frame and Grid to hold the Content#
mainframe = Frame(root)
mainframe.grid(column=0,row=0, sticky=(N,W,E,S))
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
mainframe.pack(pady = 100, padx = 100)
#Text Box to take user input#
Label(mainframe, text = "Enter text").grid(row = 2, column = 0)
var = StringVar()
textbox = Entry(mainframe, textvariable = var).grid(row = 2, column = 1)
Label(mainframe, text = "Output").grid(row = 2, column = 2)
var1 = StringVar()
textbox = Entry(mainframe, textvariable = var1).grid(row = 2, column = 3)
#Creating a button to call pig_latin function#
b = Button(mainframe, text = 'Translate', command = pig_latin).grid(row = 3, column = 1, columnspan = 3)
root.mainloop()