Creating a Language Translator Graphic User Interface (GUI) using Python and Kivy: Step-by-Step Tutorial

Posted by


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!

0 0 votes
Article Rating
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@MrELMOSAFER
2 months ago

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

@gauthams1499
2 months ago

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

@mrtherapy309
2 months ago

Its always the small channels that give you solutions. Thanks

@abcde7515
2 months ago

👍