借用google的翻譯功能
from googletrans import Translator
主模組參數設定
class tesserectOCR():
def __init__(self, master):
self.parent = master
self.color_1 = (0,0,0)
self.color_2 = (0,0,0)
self.imageFile = str()
self.tesserectOCRPanel = tk.LabelFrame(self.parent,
text="tesserect OCR",
font=('Courier', 10))
self.tesserectOCRPanel.pack(side=tk.TOP)
self.init_tesserect_tab()
self.init_setting_tab()
self.init_Font_tab()
self.init_GoogleTran_tab()
self.init_DisplaySceneMarkInfo_tab()
def tesseract_OCR(self, event = None):
.
.
.
def init_tesserect_tab(self):
.
.
.
def googleTrans(self, event = None):
.
.
.
google翻譯面板設置
def init_GoogleTran_tab(self):
self.GoogleTran_tab = tk.Frame(self.tesserectOCRPanel)
self.GoogleTran_tab.pack(side = tk.TOP,
expand=tk.YES,
fill=tk.BOTH)
self.googleTrans_Button = tk.Button(self.GoogleTran_tab,
text = "Google Translate",
font=('Courier', 10),
command = self.googleTrans)
self.googleTrans_Button.pack(side=tk.LEFT, expand=tk.NO, fill = tk.X)
self.dest_langType = ttk.Combobox(self.GoogleTran_tab,
font=('Courier', 10),
width = 25,
values = ["en",
"zh-CN",
"ja",
"ko",
"ar"],
state = "readonly")
self.dest_langType.pack(side=tk.LEFT, expand=tk.NO, fill = tk.X)
self.dest_langType.current(0)
def init_Font_tab(self):
.
.
.
def init_setting_tab(self):
.
.
.
顯示資訊
def init_DisplaySceneMarkInfo_tab(self):
self.DisplaySceneMarkInfo_Frame = tk.LabelFrame(self.tesserectOCRPanel,
text="Display tesseract OCR and Translation Info",
font=('Courier', 9))
self.DisplaySceneMarkInfo_Frame .pack(side=tk.TOP, expand=tk.NO)
self.DisplaySceneMarkInfo = tk.Text(
self.DisplaySceneMarkInfo_Frame,
width = 70,
height = 7)
DisplaySceneMarkInfo_sbarV = Scrollbar(
self.DisplaySceneMarkInfo_Frame,
orient=tk.VERTICAL)
DisplaySceneMarkInfo_sbarH = Scrollbar(
self.DisplaySceneMarkInfo_Frame,
orient=tk.HORIZONTAL)
DisplaySceneMarkInfo_sbarV.config(
command=self.DisplaySceneMarkInfo.yview)
DisplaySceneMarkInfo_sbarH.config(
command=self.DisplaySceneMarkInfo.xview)
self.DisplaySceneMarkInfo.config(
yscrollcommand=DisplaySceneMarkInfo_sbarV.set)
self.DisplaySceneMarkInfo.config(
xscrollcommand=DisplaySceneMarkInfo_sbarH.set)
DisplaySceneMarkInfo_sbarV.pack(side=tk.RIGHT, fill=tk.Y)
DisplaySceneMarkInfo_sbarH.pack(side=tk.BOTTOM, fill=tk.X)
self.DisplaySceneMarkInfo.pack(side=tk.TOP, expand=tk.NO)
DisplaySceneMarkInfoCLEAR =tk.Button(self.tesserectOCRPanel,
text = "Clear",
font=('Courier', 9),
command = self.DisplaySceneMarkInfoCLEAR)
DisplaySceneMarkInfoCLEAR.pack(side=tk.TOP, expand=tk.NO)
def DisplaySceneMarkInfoCLEAR(self, event = None):
.
.
.
文字
!
翻譯