Skip to content

Commit ddf4c5b

Browse files
Create main.py
1 parent be172af commit ddf4c5b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

Translate-App/main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/python3
2+
# Translator App v1.0
3+
#
4+
5+
from PyQt5.QtWidgets import *
6+
from PyQt5.QtCore import *
7+
from PyQt5.QtGui import *
8+
from PyQt5.uic import loadUi
9+
10+
import sys,googletrans
11+
12+
class Window(QMainWindow):
13+
def __init__(self):
14+
super(Window,self).__init__()
15+
loadUi("./Form/page.ui",self)
16+
self.setWindowTitle("Translator App")
17+
self.setWindowIcon(QIcon("./icon/translate-icon.png"))
18+
19+
self.exit_action.setShortcut("Alt+f4")
20+
self.exit_action.setWhatsThis("Exit")
21+
self.exit_action.setStatusTip("Exit")
22+
self.exit_action.triggered.connect(self.close)
23+
24+
self.help_action.triggered.connect(self.help)
25+
self.about_action.triggered.connect(self.about)
26+
self.feedback_action.triggered.connect(self.feedback)
27+
28+
self.clear_btn.clicked.connect(self.clear_all_txt)
29+
self.translate_btn.clicked.connect(self.translate)
30+
31+
self.statusBar().addWidget(QLabel("Translate App v1.0",self))
32+
33+
self.add_language()
34+
def add_language(self):
35+
for lang in googletrans.LANGUAGES.values():
36+
self.combo.addItem(lang.capitalize())
37+
self.combo_2.addItem(lang.capitalize())
38+
39+
self.combo.setCurrentText("Persian")
40+
self.combo_2.setCurrentText("English")
41+
def translate(self):
42+
self.text = self.txt.toPlainText()
43+
self.fromlang = self.combo.currentText()
44+
self.tolang = self.combo_2.currentText()
45+
translator = googletrans.Translator()
46+
translate_ = translator.translate(self.text,src=self.fromlang,dest=self.tolang)
47+
self.txt2.setText(translate_.text)
48+
49+
def clear_all_txt(self):
50+
self.txt.clear()
51+
self.txt2.clear()
52+
53+
def help(self):
54+
pass
55+
56+
def about(self):
57+
pass
58+
59+
def feedback(self):
60+
pass
61+
62+
def main():
63+
# Translator App v1.0
64+
app = QApplication(sys.argv)
65+
app.setApplicationName("Translator App")
66+
app.setApplicationVersion("v1.0")
67+
window = Window()
68+
window.show()
69+
sys.exit(app.exec_())
70+
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)