Hilfe bei Dictonary

I’m trying to create a dictonary that searches for words and adds unknown words to a file. The error index out of range occurs. How can I solve this? I want create a translator. A translator for crochet pattern. The abbreviation from other language like inc=increase should be translatet to Zun = Zunnehmen in german. Thats why i cant use google or so on.+

#/usr/bin/python3
woerter = {}
fobj = open("woerterbuch.txt", "r")
for line in fobj: 
    line = line.strip()
    zuordnung = line.split(" ")
    woerter[zuordnung[0]] = zuordnung[1] 

while True: 
    wort = input("Please insert a word: ")
    if wort in woerter: 
        print("The german word means:", woerter[wort]) 
    else: 
        print("The word is unknown")
        print ("Please insert the translation")
        for engl in woerter:
            fobj.write("{} {}\n".format(engl, woerter[engl]))
fobj.close()        
michi@localhost ~/python $ less woerterbuch.txt 
sc fM inc Zun

try:
import Tkinter as tk
except:
import tkinter as tk

liste={"sc":"fM","inc":"Zun","dec":"Abn"}
def uebersetzung():
wort=str(e1.get())
if wort in liste:
print ("Ja, vorhanden, die Übersetzung ist")
else:
print ("Nein, noch nicht vorhanden")

def popupmsg():
popup = tk.Tk()
popup.wm_title("!")
label = Label(popup, text="Übersetzung:")
label.pack(side="top", fill="x", pady=10)
B1 = Button(popup, text="Okay", command = popup.destroy)
B1.pack()
popup.mainloop()

root = tk.Tk()
root.geometry("300x300")
make Esc exit the program

root.bind('', lambda e: root.destroy())

logo=PhotoImage(file="../../../../home/michi/python/kruemelmonster.png")
w=Label(root,compound=CENTER,image=logo)
w.pack()
e1=Entry(master=root)
e1.pack()
button=tk.Button(master=root,text="Exit", command=uebersetzung)
button.pack()
button1=Button(master=root,text="Übersetzen", command=popupmsg)
button1.pack()
root.mainloop()


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.