Wednesday, July 3, 2024
HomeLanguagesPythonLanguage Detection in Python using Tkinter

Language Detection in Python using Tkinter

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:

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments