构建一个应用程序,用Python将英语翻译成印地语
在这些文章中,我们将编写Python脚本将英语单词翻译成印地语单词并将其与 GUI 应用程序绑定。我们正在使用englisttohindi模块将英语单词翻译成印地语单词。
安装:
将此代码运行到您的终端中:
pip install englisttohindi
方法:
- 导入 englisttohindi 模块。
- 通过传递消息创建 EngtoHindi() 的对象。
- 使用 convert() 方法进行翻译。
例子:
Python3
# importing the module
from englisttohindi.englisttohindi import EngtoHindi
# message to be translated
message = "Yes, I am geeks"
# creating a EngtoHindi() object
res = EngtoHindi(message)
# displaying the translation
print(res.convert)
Python3
# import modules
from tkinter import *
from englisttohindi.englisttohindi import EngtoHindi
# user define function
def eng_to_hindi():
trans = EngtoHindi(str(e.get()))
res = trans.convert
result.set(res)
# object of tkinter
# and background set for grey
master = Tk()
master.configure(bg = 'light grey')
# Variable Classes in tkinter
result = StringVar();
# Creating label for each information
# name using widget Label
Label(master, text="Enter Text : " , bg = "light grey").grid(row = 0, sticky = W)
Label(master, text="Result :", bg = "light grey").grid(row = 3, sticky = W)
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=result,bg = "light grey").grid(row = 3,
column = 1,
sticky = W)
e = Entry(master, width = 100)
e.grid(row = 0, column = 1)
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text = "Show", command = eng_to_hindi, bg = "Blue")
b.grid(row = 0, column = 2, columnspan = 2, rowspan = 2, padx = 5, pady = 5,)
mainloop()
输出:
हां, मैं गीक्स हूं
使用 Tkinter 的英语到印地语翻译器应用程序:此脚本将上述实现实现到 GUI 中。
蟒蛇3
# import modules
from tkinter import *
from englisttohindi.englisttohindi import EngtoHindi
# user define function
def eng_to_hindi():
trans = EngtoHindi(str(e.get()))
res = trans.convert
result.set(res)
# object of tkinter
# and background set for grey
master = Tk()
master.configure(bg = 'light grey')
# Variable Classes in tkinter
result = StringVar();
# Creating label for each information
# name using widget Label
Label(master, text="Enter Text : " , bg = "light grey").grid(row = 0, sticky = W)
Label(master, text="Result :", bg = "light grey").grid(row = 3, sticky = W)
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=result,bg = "light grey").grid(row = 3,
column = 1,
sticky = W)
e = Entry(master, width = 100)
e.grid(row = 0, column = 1)
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text = "Show", command = eng_to_hindi, bg = "Blue")
b.grid(row = 0, column = 2, columnspan = 2, rowspan = 2, padx = 5, pady = 5,)
mainloop()
输出: