1

I'm using python. There's an entry that with the code entry.get() I'm going to translate the sentence that the user types.

from googletrans import Translator
from tkinter import *
translator = Translator()
root = Tk()
translator = Translator()
root.resizable(0, 0)
root.geometry('300x200')
l1 = Label(root, text='Text (In any language you want)')
l1.grid(row=1, column=1, padx=10, pady=10)
e1 = Entry(root)
e1.place(x=10, y=30, width=280, height=20)
the_text = e1.get()
translation = translator.translate(the_text, dest='en')
print(translation.text)
mainloop()

And it doesn't work because of:

    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

So the error is for the line translation = translator.translate(the_text, dest='en')

I have to tell you that I even tried translation=translator.translate("hermana", dest='en') as translation = translator.translate(the_text, dest='en') and it worked. So the problem IS about this that it can not translate the result of the entry...

How can I fix this???

Yangelixx
  • 53
  • 9
  • The first issue that I can see is that you are calling `e1.get()` just after you create your `Entry`. The user hasn't had enough time to input any text in the entry. Add a button that actually calls `e1.get()` and `translator.translate(...)` – TheLizzard Sep 02 '21 at 12:04

2 Answers2

2

Googletrans module has stopped working for some reason.

See this: Why "Googletrans.Translator" suddenly stopped working?

IJ_123
  • 457
  • 6
  • 13
1

From the error I see that the_text is NoneType.
This actually means that the_text = e1.get() doesn't work, returns nothing

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • 1
    `e1.get()` is guaranteed to be a `str`ing or raise an exception if the `Entry` widget has been destroyed. – TheLizzard Sep 02 '21 at 12:05