这是我的代码。我正在尝试创建简单的GUI词典。但是出现以下错误
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from PyDictionary import PyDictionary
from googletrans import Translator
from PIL import ImageTk,Image
root=tk.Tk()
root.title('My Dictionary')
root['bg']='grey'
root.geometry("800x600")
#frame=Frame(root,width='200',height='200',borderwidth='1',relief=RIDGE)
#frame.grid(sticky='W')
def get_meaning():
dictionary=PyDictionary()
get_word=entry.get()
languages=language.get()
if get_word=="":
messagebox.showerror('Dictionary','Please write the word')
elif dictionary=="English To English":
d=dictionary.meaning(get_word)
output.insert('end',d.text)
elif dictionary=="English To Urdu":
translator=Translator()
t=translator.translate(get_word,dest='hi')
output.insert('end',t.text)
def quit():
root.destroy()
word=Label(root,text="Enter Word Please",bg='white',font=('verdana',10,'bold'))
word.place(x=350,y=200)
a=tk.StringVar()
language=ttk.Combobox(root,width=20,text='a',font=('verdana',10,'bold'),state='readonly')
language['values']=('English To English',
'English To Urdu',
)
language.place(x=580,y=150,anchor='center')
language.current=0
entry=Entry(root,width=50,borderwidth=2,relief='ridge')
entry.place(x=500,y=200,anchor='nw')
search=Button(root,text='SEARCH',font=('verdana',10,'bold'),cursor='hand2',relief=RIDGE,command=get_meaning)
search.place(x=430,y=250)
quit=Button(root,text='QUIT',font=('verdana',10,'bold'),cursor='hand2',relief=RIDGE,command=quit)
quit.place(x=510,y=250)
meaning=Label(root,text='MEANING',font=('verdana',10,'bold'),cursor='hand2',relief=RIDGE,bg='white')
meaning.place(x=350,y=300)
output=Text(root,height=8,width=40,borderwidth=2,relief='ridge')
output.place(x=350,y=325)
root.mainloop()
错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Ahmad Hashmi\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/Ahmad Hashmi/Desktop/6th semester/DM/p.py", line 22, in get_meaning
elif dictionary=="English To English":
TypeError: __eq__() takes 1 positional argument but 2 were given
答案 0 :(得分:0)
实际上,当您在程序中使用x == z时,将调用__eq__。您只是将一堆值与一个值进行比较。您无法将字典与字符串进行比较。为此,必须一一比较这些值。