In this tutorial, we will walk you through the steps to build a language translator GUI using Python and Kivy. Kivy is an open-source Python library for building multi-touch applications that can run on various platforms like Windows, macOS, Linux, iOS, and Android.
First, let’s install the required libraries:
pip install kivy googletrans==4.0.0-rc1
Now, let’s start by creating a new Python file named translator_app.py
and import the necessary modules:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from googletrans import Translator
Next, let’s define a class for our translator app:
class TranslatorApp(App):
def build(self):
self.translator = Translator()
layout = BoxLayout(orientation='vertical')
self.input_text = TextInput(hint_text='Enter text to translate')
layout.add_widget(self.input_text)
self.output_text = Label(text='')
layout.add_widget(self.output_text)
translate_button = Button(text='Translate')
translate_button.bind(on_press=self.translate_text)
layout.add_widget(translate_button)
return layout
Now, let’s implement the translate_text
method that will handle the translation process:
def translate_text(self, instance):
input_text = self.input_text.text
translated_text = self.translator.translate(input_text, dest='en').text
self.output_text.text = translated_text
Lastly, let’s add the run
method to run our translator app:
if __name__ == '__main__':
TranslatorApp().run()
That’s it! You have successfully built a language translator GUI using Python and Kivy. To run the app, simply execute the translator_app.py
file in your Python environment. You can enter any text in the input field and click the "Translate" button to see the translated text in English. Feel free to customize the app further by adding more languages or functionalities!
thanks so much… there is some hacks in kivy to display Arabic and eastern languages but using pango library from kivy garden you can find some notation for it in the docs especially in [ Label , Text Input] but it needs some more study to figure it ….
Good luck
Bro can you upload the code too. Needed to refer this as I am creating a language translator that translates text to speech, image to text and speech to text. By the way your video did help me in certain places…. <3
Its always the small channels that give you solutions. Thanks
👍