Python:
from tkinter import *
from googletrans import Translator
def tran():
text = t.get('1.0', END)
a = translator.translate(text, dest='en')
t1.delete('1.0', END)
t1.insert('1.0', a.text)
root = Tk()
root.geometry('500x350')
root.title('Переводчик')
root.resizable(width=False, height=False)
root['bg'] = 'black'
translator = Translator()
label = Label(root, fg='white', bg='black', font='Arial 15 bold', text='Введите текст на русском')
label.place(relx=0.5, y=30, anchor=CENTER)
t = Text(root, width=35, height=5, font='Arial 12 bold')
t.place(relx=0.5, y=100, anchor=CENTER)
btn = Button(root, width=45, text='Перевести', command=tran)
btn.place(relx=0.5, y=180, anchor=CENTER)
t1 = Text(root, width=35, height=5, font='Arial 12 bold')
t1.place(relx=0.5, y=260, anchor=CENTER)
root.mainloop()
И ошибка:
Код:
Exception in Tkinter callback
Traceback (most recent call last):
File "F:\Python\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\PC\PycharmProjects\переводчик\main.py", line 7, in tran
a = translator.translate(text, dest='en')
File "C:\Users\PC\PycharmProjects\переводчик\venv\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\PC\PycharmProjects\переводчик\venv\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\PC\PycharmProjects\переводчик\venv\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\PC\PycharmProjects\переводчик\venv\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'