问题与googletrans模块



我正在尝试使用googletrans在python中制作一个小型图形翻译器。它运行良好,直到我按下翻译按钮这是我得到的错误信息

Exception in Tkinter callback
Traceback (most recent call last):
File "C:pythonlibtkinter__init__.py", line 1884, in __call__
return self.func(*args)
File "C:UserslenueOneDriveDesktoprun.py", line 36, in run
translation = translator.translate('How are you', src= 'en', dest = 'fr')
File "C:pythonlibsite-packagesgoogletransclient.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:pythonlibsite-packagesgoogletransclient.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:pythonlibsite-packagesgoogletransgtoken.py", line 194, in do
self._update()
File "C:pythonlibsite-packagesgoogletransgtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

我正在使用一个不同的模块,但有导入问题,所以我安装了googletrans这是我所有的代码

import os
from googletrans import Translator
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
class Window(object):
def __init__(self, master):
frame = Frame(master)
frame.grid()
self.options = ['French' , 'English' , 'Spansih']
self.text_label = Label(root, text="Enter text : ")
self.text_label.grid(column = 0, row = 0)
self.imput = Entry(root)
self.imput.grid(column = 1, row = 0)
self.selection_frame = LabelFrame(root, text = "Languages")
self.selection_frame.grid(column = 0, row = 1, columnspan = 2)
self.langs = ttk.Combobox(self.selection_frame, values = self.options)
self.langs.grid(column = 0, row = 1)
self.result = Label(root, text = "")
self.result.grid(column = 0, row = 2, columnspan = 2)
self.button = Button(root, text = "Translate", command = self.run)
self.button.grid(column = 0, row = 3, columnspan = 2)
def run(self):
translator = Translator()
text = self.imput.get()
lang = self.langs.get()
if lang == 'French':
lc = 'fr'
if lang == 'English':
lc = 'en'
if lang == 'Spanish':
lc = 'es'
translation = translator.translate(text, dest = lc)
self.result.configure(text = translation)
root = Tk()
root.title = ("run")
Window(root)
root.mainloop()

您应该升级到3.1.0a0版本他们已经对这个问题做了临时修复

运行pip install googletrans==3.1.0a0

只要安装alpha版googletrans与pip install googletrans==3.1.0a0

其他版本似乎不工作,因为一些错误。同样的问题也在github上讨论过。

关于文档,它与googletrans相同

相关内容

  • 没有找到相关文章

最新更新