Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish all feature #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 189 additions & 23 deletions Run
Original file line number Diff line number Diff line change
@@ -1,26 +1,192 @@
import tkinter as tk
from tkinter import ttk

from googletrans import Translator
translator = Translator()

choice = 0
while choice != 5:
choice = int(input("Enter your choice:"))

if choice == 1:
Userinput = input("Text that you want to translate:")
Languages = input("Language that you want to translate to:")
t1 = translator.translate(Userinput, dest=Languages)
t2 = translator.translate(Userinput, dest='ko')
t3 = translator.translate(Userinput, dest='th')
t1.text
t2.text
t3.text
print(t1.text)
print(t2.text)
print(t3.text)

elif choice == 6:
print("bye bye")
break

else:
print(f'{choice} '"(The number is invalid, Please enter again)\n")
#read the history amd favorite file and put it into list
try:
with open('history.txt', 'r') as h:
hl = [line.strip() for line in h]

except:
hl = []

try:
with open('favorite.txt', 'r') as f:
fl = [line.strip() for line in f]

except:
fl = []

def getinput(Userinput,tranto1, tranto2,tranto3):

hl.append(Userinput) # put the user input in the list
listbox.insert(tk.END, Userinput) #update the history listbox
with open('history.txt', 'w') as j: #save the text into the file
j.write('\n'.join(hl))

t1 = translator.translate(Userinput, dest=tranto1)
t2 = translator.translate(Userinput, dest=tranto2)
t3 = translator.translate(Userinput, dest=tranto3)
lang1 = t1.text
lang2 = t2.text
lang3 = t3.text
D_t1 =tk.Label(lang1frame,text="" + lang1) #display the result on GUI
D_t1.place(relx=0,rely=0,relwidth=1, relheight=1)
D_t2 = tk.Label(lang2frame, text="" + lang2) #display the result on GUI
D_t2.place(relx=0, rely=0, relwidth=1, relheight=1)
D_t3 = tk.Label(lang3frame, text="" + lang3) #display the result on GUI
D_t3.place(relx=0, rely=0, relwidth=1, relheight=1)

def selectlist(event):
# get selected text
select = listbox.curselection()[0]
# get the line tex
text_select = listbox.get(select)

# delete previous text in the entry
entry.delete(0, 50)
# display the selected text in the entry box
entry.insert(0, text_select)


def selectlist2(event):
# get selected text
select2 = listbox2.curselection()[0]
# get the line text
text_select2 = listbox2.get(select2)
# delete previous text in the entry
entry.delete(0, 50)
# display the selected text in the entry box
entry.insert(0, text_select2)

def getfavorite(Addword):
fl.append(Addword) #put the favorite word into the list
listbox2.insert(tk.END, Addword) #update the listbox
with open('favorite.txt', 'w') as k: #save the favorite word into the file
k.write('\n'.join(fl))

HEIGHT = 350
WIDTH = 450

root = tk.Tk()
#Create the GUI windows
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

#set frame and backgroud color
frame = tk.Frame(root, bg='#d8d8da')
frame.place(relwidth=1, relheight=1)

#translate button and add favorite
btn = tk.Button(root, text='Translate', font=('arial',15,'bold'), fg='black', bg='gray',
command=lambda: getinput(entry.get(),combobox1.get(),combobox2.get(),combobox3.get()))
btn.place(relx=0.42, rely=0.26,)

btn = tk.Button(root, text='Add Favorite', font=('arial',14,'bold'), fg='black', bg='gray',
command=lambda: getfavorite(entry.get()))
btn.place(relx=0.40, rely=0.34,)

#text display on GUI
text1 = tk.Label(frame, text='Python Translate App', font=('arial',20,'bold'),fg='black',bg='#d8d8da')
text1.pack()

text2 = tk.Label(frame, text='Input word to translate:', font=('arial',16,'bold'), bg='#d8d8da',fg='black')
text2.place(relx =0, rely=0.18)

#entry for get input
entry = tk.Entry(frame,bg='white',justify='left',)
entry.place(relx=0, rely=0.25,relwidth=0.38)

#combobox
combobox1 = ttk.Combobox(frame, values=['afrikaans','albanian','amharic','arabic','armenian','azerbaijani','basque',
'belarusian','bengali','bosnian','bulgarian','catalan','cebuano','chichewa',
'chinese (simplified)','chinese (traditional)','corsican','croatian','czech',
'danish','dutch','english','esperanto','estonian','filipino','finnish','french',
'spanish','sundanese','swahili','swedish','tajik','tamil','telugu','thai',
'turkish','ukrainian','urdu','uzbek','vietnamese','welsh','xhosa','yiddish',
'yoruba','zulu','Filipino','Hebrew'])
combobox1.place(relx=0.69, rely=0.20, relwidth=0.31)

text3 = tk.Label(frame, text='To:', font=('arial',16,'bold'), bg='#d8d8da',fg='black')
text3.place(relx=0.60, rely=0.20)

lang1frame = tk.Frame(root, bg='white')
lang1frame.place(relx =0.62, rely=0.28, relwidth=0.38, relheight=0.15)

combobox2 = ttk.Combobox(frame, values=['afrikaans','albanian','amharic','arabic','armenian','azerbaijani','basque',
'belarusian','bengali','bosnian','bulgarian','catalan','cebuano','chichewa',
'chinese (simplified)','chinese (traditional)','corsican','croatian','czech',
'danish','dutch','english','esperanto','estonian','filipino','finnish','french',
'frisian','galician','georgian','german','greek','gujarati','haitian creole',
'hausa','hawaiian','hebrew','hindi','hmong','hungarian','icelandic','igbo',
'indonesian','irish','italian','japanese','javanese','kannada','kazakh','khmer',
'korean','kurdish (kurmanji)','kyrgyz','lao','latin','latvian','lithuanian',
'luxembourgish','macedonian','malagasy','malay','malayalam','maltese','maori',
'marathi','mongolian','myanmar (burmese)','nepali','norwegian','pashto','persian',
'polish','portuguese','punjabi','romanian','russian','samoan','scots gaelic',
'serbian','sesotho','shona','sindhi','sinhala','slovak','slovenian','somali',
'spanish','sundanese','swahili','swedish','tajik','tamil','telugu','thai',
'turkish','ukrainian','urdu','uzbek','vietnamese','welsh','xhosa','yiddish',
'yoruba','zulu','Filipino','Hebrew'])
combobox2.place(relx=0.69, rely=0.44, relwidth=0.31)

text4 = tk.Label(frame, text='To:', font=('arial',16,'bold'), bg='#d8d8da',fg='black')
text4.place(relx=0.60, rely=0.44)

lang2frame = tk.Frame(root, bg='white')
lang2frame.place(relx =0.62, rely=0.52, relwidth=0.38, relheight=0.15)

combobox3 = ttk.Combobox(frame, values=['afrikaans','albanian','amharic','arabic','armenian','azerbaijani','basque',
'belarusian','bengali','bosnian','bulgarian','catalan','cebuano','chichewa',
'chinese (simplified)','chinese (traditional)','corsican','croatian','czech',
'danish','dutch','english','esperanto','estonian','filipino','finnish','french',
'frisian','galician','georgian','german','greek','gujarati','haitian creole',
'hausa','hawaiian','hebrew','hindi','hmong','hungarian','icelandic','igbo',
'indonesian','irish','italian','japanese','javanese','kannada','kazakh','khmer',
'korean','kurdish (kurmanji)','kyrgyz','lao','latin','latvian','lithuanian',
'luxembourgish','macedonian','malagasy','malay','malayalam','maltese','maori',
'marathi','mongolian','myanmar (burmese)','nepali','norwegian','pashto','persian',
'polish','portuguese','punjabi','romanian','russian','samoan','scots gaelic',
'serbian','sesotho','shona','sindhi','sinhala','slovak','slovenian','somali',
'spanish','sundanese','swahili','swedish','tajik','tamil','telugu','thai',
'turkish','ukrainian','urdu','uzbek','vietnamese','welsh','xhosa','yiddish',
'yoruba','zulu','Filipino','Hebrew'])
combobox3.place(relx=0.69, rely=0.68, relwidth=0.31)

text5 = tk.Label(frame, text='To:', font=('arial',16,'bold'), bg='#d8d8da',fg='black')
text5.place(relx=0.60, rely=0.68)

lang3frame = tk.Frame(root, bg='white')
lang3frame.place(relx =0.62, rely=0.76, relwidth=0.38, relheight=0.15)

listbox = tk.Listbox(root)
listbox.place(relx=0, rely=0.41, relheight=0.25)

listbox2 = tk.Listbox(root)
listbox2.place(relx=0, rely=0.74, relheight=0.25)

#scrollbar
scroll = tk.Scrollbar(command=listbox.yview, orient='vertical')
scroll.place(relx=0.365, rely=0.415, relheight=0.24)
listbox.configure(yscrollcommand=scroll.set)

scroll2 = tk.Scrollbar(command=listbox.yview, orient='vertical')
scroll2.place(relx=0.365, rely=0.745, relheight=0.24)
listbox2.configure(yscrollcommand=scroll.set)

#insert the data from history and favorite .txt into listbox
for i in hl:
listbox.insert(tk.END, i)

for j in fl:
listbox2.insert(tk.END, j)

#make the action when click button
listbox.bind('<ButtonRelease-1>', selectlist)
listbox2.bind('<ButtonRelease-1>', selectlist2)

root.mainloop()


1 change: 1 addition & 0 deletions favorite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eat
3 changes: 2 additions & 1 deletion googletrans/gtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def acquire(self, text):
# assume e means char code array
e = []
g = 0
size = len(text)
#size = len(text)
size = len(a)
while g < size:
l = a[g]
# just append if l is less than 128(ascii: DEL)
Expand Down
3 changes: 3 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go
eat
fly