Exception in Tkinter callback Traceback most recent call last

0 votes
from tkinter import *
from tkinter import ttk
from googletrans import Translator, LANGUAGES

root = Tk()
root.geometry(‘1080×400′)
root.resizable(0, 0)
root.title(“Python Project | Language Translator”)
root.config(bg=’ghost white’)

# heading
Label(root, text=”Where Communication Is The Key”, font=”arial 20 bold”, bg=’white smoke’).pack()
Label(root, text=”Language Translator”, font=’arial 20 bold ‘, bg=’white smoke’, width=’20’).pack(side=’bottom’)

# INPUT AND OUTPUT TEXT WIDGET
Label(root, text=”Enter Text”, font=’arial 13 bold’, bg=’white smoke’).place(x=200, y=60)
Input_text = Text(root, font=’arial 10′, height=11, wrap=WORD, padx=5, pady=5, width=60)
Input_text.place(x=30, y=100)

Label(root, text=”Output”, font=’arial 13 bold’, bg=’white smoke’).place(x=780, y=60)
Output_text = Text(root, font=’arial 10′, height=11, wrap=WORD, padx=5, pady=5, width=60)
Output_text.place(x=600, y=100)

##################
Language = list(LANGUAGES.values())

src_lang = ttk.Combobox(root, values=Language, width=22)
src_lang.place(x=20, y=60)
src_lang.set(‘choose input language’)

dest_lang = ttk.Combobox(root, values=Language, width=22)
dest_lang.place(x=890, y=60)
dest_lang.set(‘choose output language’)

######## Define function #######

def Translate():
translator = Translator()
translated = translator.Translate(text=Input_text.get(1.0, END), src=src_lang.get(), dest=dest_lang.get())
Output_text.delete(1.0, END)
Output_text.insert(END, translated.text)

########## Translate Button ########
trans_btn = Button(root, text=’Translate’, font=’arial 12 bold’, pady=5, command=Translate, bg=’royal blue1′,
activebackground=’sky blue’)
trans_btn.place(x=490, y=180)

root.mainloop()

below is the error: Please solve this

Traceback (most recent call last):
File “C:\Users\tahir\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py”, line 1883, in __call__
return self.func(*args)
File “C:/Users/tahir/PycharmProjects/firstProject/main.py”, line 43, in Translate
Output_text.insert(END, translated.text)
AttributeError: ‘NoneType’ object has no attribute ‘text’
Dec 19, 2020 in Python by R
• 120 points
20,351 views

1 answer to this question.

0 votes

Hello, @R,

As per the Beautiful Soup Documentation:

AttributeError: 'NoneType' object has no attribute 'foo' - This usually happens because you called find() and then tried to access the .foo attribute of the result. But in your case, find() didn’t find anything, so it returned None, instead of returning a tag or a string. You need to figure out why your find() call isn’t returning anything.

It could not find an element you searched for at this line, and returned None: post_title = post.find(class_='a-section').text

answered Dec 21, 2020 by Gitika
• 65,770 points

Related Questions In Python

0 votes
1 answer

ImportError Traceback (most recent call last) ImportError: numpy.core.umath failed to import

Hi@akhtar, You need to upgrade your Numpy library. Your ...READ MORE

answered Jun 23, 2020 in Python by MD
• 95,460 points
3,010 views
0 votes
0 answers

Python Traceback (most recent call last)

The error message: Traceback (most recent call last): ...READ MORE

May 12, 2022 in Python by Kichu
• 19,040 points
3,267 views
0 votes
1 answer

Replace First and Last Word of String in the Most Pythonic Way

import re a = " this is a ...READ MORE

answered Aug 23, 2018 in Python by aryya
• 7,460 points
2,972 views
0 votes
2 answers

Manually raising (throwing) an exception in Python

Exception handling issues in python can easily ...READ MORE

answered Jan 18, 2019 in Python by nick
• 140 points
17,553 views
0 votes
1 answer

Call a shell command in Python?

Try this - os.system("commands and arguments") READ MORE

answered Jun 21, 2018 in Python by Hamartia's Mask
• 1,580 points
790 views
0 votes
1 answer

Is there a way of using .lower more effectively in tkinter?

Here is a simple function and some ...READ MORE

answered Sep 25, 2018 in Python by Priyaj
• 58,020 points
2,394 views
0 votes
1 answer

How to capture exception message in Python

You have to define which type of ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 58,020 points
826 views
+1 vote
4 answers

How to install tkinter in pycharm?

Ya, this is a problem with installing ...READ MORE

answered Apr 4, 2019 in Python by Jishan
87,928 views
0 votes
2 answers

How to call perl script in Python script?

If you just want to open a ...READ MORE

answered Oct 7, 2020 in Python by Reshma
13,594 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP