0

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

4
  • 1
    Please copy and paste your error into the question, instead of just leaving a link. For more info, go to how to ask. Commented Mar 4, 2023 at 12:20
  • Have you tried printing the parameters and seeing if they are not None? Commented Mar 4, 2023 at 12:21
  • No, I have not tried it yet, can you tell me which parameter you are talking about Commented Mar 4, 2023 at 13:59
  • Why do you have duplicated lab_txt? Use different variable Commented Mar 11, 2023 at 10:54

1 Answer 1

0

It's a bug in googletrans. You can find its description on GitHub. At this moment, you have to install a future version of that module to be able to run it.

In your environment, you have to run this command to upgrade googletrans as described in this comment on GitHub:

pip install googletrans==4.0.0rc1

After installing that version, you should be able to run your code without this error message.


But your will see another malfunction when you will run your code. You should change your code in the function change() from return trans1 to return trans1.text. It should look a little bit like:

def change(text="Type", src="English", dest="Hindi"):
    text1=text
    ⋮
    trans1= trans.translate(text,src=src1,dest=dest1)
    return trans1.text
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.