I am trying to create a translator with help of Tkinter and googletrans library but getting following error and I am confuse as I am not sure is this error due to library or a mistake from my side.
from tkinter import *
from tkinter import ttk
from googletrans import Translator,LANGUAGES
def change(text="Type", src="English", dest="Hindi"):
text1=text
src1=src
dest1=dest
trans= Translator()
trans1= trans.translate(text,src=src1,dest=dest1)
return trans1
def data():
s = comb_sor.get()
d = comb_dest.get()
msg= Sor_txt.get(1.0,END)
textget = change(text= msg, src=s, dest=d)
dest_txt.delete(1.0,END)
dest_txt.insert(END,textget)
root = Tk()
root.title("Translator")
root.geometry("500x700")
root.config(bg='#f1f3f5')
lab_txt=Label(root, text="Translator", font=("Inter", 30, "bold"), bg="#f1f3f5", fg="#495057")
lab_txt.place(x=100, y=40, height=50, width=300)
frame = Frame(root).pack(side=BOTTOM)
lab_txt=Label(root, text="Source Text", font=("Inter", 16, "bold"), bg="#f1f3f5", fg="#495057")
lab_txt.place(x=100, y=100, height=30, width=300)
Sor_txt = Text(frame, font=("Inter", 18, "bold"), bg="#f1f3f5", wrap=WORD)
Sor_txt.place(x=10, y=130, height=150, width=480)
list_text = list(LANGUAGES.values())
comb_sor = ttk.Combobox(frame, value=list_text)
comb_sor.place(x=10, y=300, height=40, width=150)
comb_sor.set("English")
button_change = Button(frame, text="Translate", relief=RAISED, command=data)
button_change.place(x=170, y=300, height=40, width=150)
comb_dest = ttk.Combobox(frame, value=list_text)
comb_dest.place(x=330, y=300, height=40, width=150)
comb_dest.set("English")
lab_txt=Label(root, text="Destination Text", font=("Inter", 16, "bold"), bg="#f1f3f5", fg="#495057")
lab_txt.place(x=100, y=360, height=30, width=300)
dest_txt = Text(frame, font=("Inter", 18, "bold"), bg="#f1f3f5", wrap=WORD)
dest_txt.place(x=10, y=400, height=150, width=480)
root.mainloop()
Please find the snippet of error below
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "e:\AWS Cloud Practioner\Translator\main.py", line 17, in data
textget = change(text= msg, src=s, dest=d)
File "e:\AWS Cloud Practioner\Translator\main.py", line 10, in change
trans1= trans.translate(text,src=src1,dest=dest1)
File "C:\Users\ghago\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\ghago\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\ghago\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\ghago\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\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'
I tries installing mttinker (new to me) and changing google translate version as well but no solution is found
None?lab_txt? Use different variable