Open In App

Language Detection in Python using Tkinter

Last Updated : 25 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite: Tkinter

In this article, we will learn about language detection Using Python in Tkinter. In Simple Words, language identification is the problem of determining which natural language given content is in.

Modules Used

  • Tkinter module is used in Python to create GUI based interfaces.
  • For Language detection, we will use the langdetect Module. langdetect Module is a port of Google’s language-detection library that supports 55 languages. This module doesn’t come with Python’s standard utility modules. So, it is needed to be installed externally. To install this type the below command in the terminal.
pip install langdetect
  • The detected language output is coming in code, it is not displaying the language name. Here we will use languages Class From the iso-639 Module. This Module is used for converting language code into language name. To install run the command given below:
pip install iso-639

Approach

  • Import module
  • Create window
  • Add button
  • Add mechanism to detect language
  • Add mechanism to translate code
  • Execute code

Program:

Python3




# Import Module
from tkinter import *
from langdetect import *
from iso639 import languages
  
# Create Object
root = Tk()
  
# Set geometry
root.geometry("400x500")
  
def language_detection():
    text = T.get("1.0", 'end-1c')
  
    # Get Language code
    language_code = languages.get(alpha2=detect(text))
    l_d.config(text="Language Detected:- "+language_code.name)
  
  
# Text Box
T = Text(root)
T.pack()
  
# label
l_d = Label(root, text="Language Detected:- ")
l_d.pack(pady=10)
  
# Button
Button(root, text='Detect Language', command=language_detection).pack(pady=10)
  
# Execute Mainloop
root.mainloop()


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads