我收到此错误AttributeError:'builtin_function_or_method'对象没有属性'title'

时间:2020-08-27 18:10:37

标签: python user-interface tkinter

我可以帮些忙吗?我正在研究具有内置翻译器的字典,该翻译器可与Google API配合使用。但是我一直得到AttributeError:'builtin_function_or_method'对象没有属性'title'据我所知,此错误是由于在定义或调用函数后未加括号引起的。我已尽力检查,但仍然找不到任何东西,因此寻求帮助。

    import tkinter as tk
import json
from difflib import get_close_matches
from googletrans import Translator
translator = Translator()

> #LIB DONE#

data = json.load(open("data.json"))
def dictionary(w):
    w = w.lower
    if w in data:
        return data[w]
    elif w.title() in data:
        return data[w.title()]
    elif len(get_close_matches(w, data.keys())) > 0:
        for widget in window.winfo_children():
            widget.destroy()
        dm = tk.Label(text = "Did you mean %s instead? Enter Y if yes, enter N if not"% get_close_matches(w, data.keys())[0])
        dm.pack()
        da = tk.Entry()
        da.pack()
        da1 = da.get()
        if da1 == "Y":
            pout1 = tk.Label(text = [get_close_matches(w, data.keys())[0]])
            pout1.pack()
            
        elif da1 == "N":
            pout1 = tk.Label(text = "The word is not found on our database")
            pout1.pack()
        else :
            pout1 = tk.Label(text = "The word doesn't exist, please double check it")
            pout1.pack()

window = tk.Tk()
window.geometry("300x300")

> #GUI OPENED#

def alert():
    for widget in window.winfo_children():
        widget.destroy()

> #BUTTON CLICKED#

greeting = tk.Label(text = "Welcome to the Dictionary & Translator!")
greeting.pack()
inserttext = tk.Label(text = "Enter a word: ")
inserttext.pack()
defentry = tk.Entry()
defentry.pack()
definput = defentry.get()
button = tk.Button(window, text = "Get definition!", command = alert)
button.pack()

> #DESTROYS THE FRAME AFTER GETTING THE INPUT FOR THE WORD#

output = dictionary(definput)

> #OUTPUT

if type(output) == list:
    for item in output:
        outputlab = tk.Label(text = item)
        outputlab.pack()
    alert()
    

> #TRANSLATE#

    def yes():
        x = 1
    def no():
        x = 0
    transq = tk.Label(text = "Do you want to translate the word to another language?")
    transq.pack()
    buttony = tk.Button(window, text = "Yes", command = yes)
    buttony.pack()
    buttonn = tk.Button(window, text = "No", command = no)
    buttonn.pack()
    if x == 1:
        

> #TRANSLATION PROGRESS STARTS#

        alert()
        asking = tk.Label(text = "What language do you want to translate to ?")
        asking.pack()
        answering = tk.Entry()
        answering.pack()
        answerin = answering.get()
        def translateout():
            tresult = translator.translate(definput, src = "english", dest = answerin)
            alert()
            endout = tk.Label(text = tresult.text)
            endout.pack()
        translateout()
        
window.mainloop()




0 个答案:

没有答案