-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
178 lines (165 loc) · 5.06 KB
/
Copy pathmain.py
File metadata and controls
178 lines (165 loc) · 5.06 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from googletrans import Translator
class translator_window:
def __init__(self, root):
self.root = root
# Change the title
self.root.title("Translator")
# Change the window size
self.root.geometry("710x400")
# no resize for both directions
self.root.resizable(False, False)
# Change icon
self.root.iconbitmap('icon.ico')
# setting up comboboxes
Cb_autoDetect = ttk.Combobox(
self.root, width=20, font=('verdana', 11))
Cb_autoDetect['values'] = (
'Auto Detect',
)
Cb_autoDetect.place(x=30, y=30)
Cb_autoDetect.current(0)
self.cb_choose_langauge = ttk.Combobox(
self.root, width=20, font=('verdana', 11))
self.cb_choose_langauge['values'] = (
'Afrikaans',
'Albanian',
'Arabic',
'Armenian',
'Basque',
'Belarusian',
'Bengali',
'Bosnian',
'Bulgarian',
'Cebuano',
'Chichewa',
'Corsican',
'Croatian',
'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',
'Kinyarwanda',
'Korean',
'Kurdish',
'Kyrgyz',
'Lao',
'Latin',
'Latvian',
'Lithuanian',
'Luxembourgish',
'Macedonian',
'Malagasy',
'Malay',
'Malayalam',
'Maltese',
'Maori',
'Marathi',
'Mongolian',
'Myanmar',
'Nepali',
'Norwegian'
'Odia',
'Pashto',
'Persian',
'Polish',
'Portuguese',
'Punjabi',
'Romanian',
'Russian',
'Samoan',
'Scots Gaelic',
'Serbian',
'Sesotho',
'Shona',
'Sindhi',
'Sinhala',
'Slovak',
'Slovenian',
'Somali',
'Spanish',
'Sundanese',
'Swahili',
'Swedish',
'Tajik',
'Tamil',
'Tatar',
'Telugu',
'Thai',
'Turkish',
'Turkmen',
'Ukrainian',
'Urdu',
'Uyghur',
'Uzbek',
'Vietnamese',
'Welsh',
'Xhosa'
'Yiddish',
'Yoruba',
'Zulu',
)
self.cb_choose_langauge.place(x=457, y=30)
self.cb_choose_langauge.current(0)
# rest gui widgets
self.textbox1 = Text(root, width=40, height=15,
borderwidth=4, font=('verdana', 10), pady=5, relief=RIDGE)
self.textbox1.place(x=20, y=70)
self.textbox2 = Text(self.root, width=40, height=15,
borderwidth=4, font=('verdana', 10), pady=5, relief=RIDGE)
self.textbox2.place(x=360, y=70)
btn_show = Button(self.root, text="Translate", relief=RIDGE, borderwidth=2, font=(
'verdana', 12, 'bold'), cursor="hand2", command=self.translate, width=8)
btn_show.place(x=240, y=345)
btn_clear = Button(self.root, text="Clear", relief=RIDGE, borderwidth=2,
font=('verdana', 12, 'bold'), cursor="hand2", command=self.clear, width=8)
btn_clear.place(x=370, y=345)
def translate(self):
'''takes input from textbox1 translate it and show output through textbox2'''
txt_input = self.textbox1.get("1.0", "end-1c")
language = self.cb_choose_langauge.get()
if txt_input == '':
messagebox.showerror('Translator - error', 'please fill the box')
else:
self.textbox2.delete(1.0, 'end')
translator = Translator()
output = translator.translate(txt_input, dest=language)
self.textbox2.insert('end', output.text)
def clear(self):
'''clear textboxes data'''
self.textbox1.delete(1.0, 'end')
self.textbox2.delete(1.0, 'end')
# driver code
if __name__ == "__main__":
root = Tk()
obj = translator_window(root)
root.mainloop()