Texteingabe übersetzen
Verfasst: Montag 21. Mai 2018, 14:41
Halli, ich bin dabei ein Programm zu entwickeln, dass Häkelanleitungen übersetzt. Dafür habe ich ein dictonary erstellt. Leider bekomme ich es nicht hin ein grafisches Feld zu erstellen wo der User den Text eingibt und der dann übersetzt wird. Bitte helft mir mal.
print("Der folgende Text wurde übersetzt: ",result)
Code: Alles auswählen
from tkinter import *
import re,sys,tkinter
def ende():
sys.exit(0)
def eingabe():
eingabe = eingabefeld.get()
fenster=tkinter.Tk()
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame,
text="EXIT", fg="red",
command=ende)
self.button.pack(side=LEFT)
self.slogan = Button(frame,
text="Übersetzung starten",
command=self.write_slogan)
self.slogan.pack(side=LEFT)
def write_slogan(self):
print ("Übersetzung")
#root = Tk()
#app = App(root)
#root.mainloop()
text = str(input('Text eingeben : '))
translation_table = {'repeat 6 times':'6x wiederholen',
'sc':'fM',
'magic ring':'Fadenring',
'inc':'zun',
'in next st':'in die nächsten Maschen',
'in next 2 st':'in 2 Maschen',
'in next 8 st':'in die nächsten 8 Maschen',
'dec':'abn',
'6 sc in magic ring':'6 fM in den Fadenring',
'in the next':'in die nächsten',
'sl st' :'KM',
'in all' : 'in Alle',
'st':'Masche',
'in next':'in die nächsten',
'repeat 3 times':'3x wiederholen',
'repeat 4 times' : '4x wiederholen',
'repeat 2 times' : '2x wiederholen',
'fM in all 18 st':'fM in alle 61 Maschen',
'1inc':'1 Zun',
'2inc':'2 Zum',
'3inc':'3 Zun.',
'4inc':'4 Zun.',
'Round':'Runde',
'1sc':'1 fM',
'2sc':'2 fM',
'3sc':'3 fM',
'4sc':'4 fM',
'5sc':'5 fM',
'6sc':'6 fM',
'7sc':'7 fM',
'Repeat':'wiederholen',
'MR':'Fadenring',
'times':'mal',
'single crochet':'feste Masche',
'Legs':'Füße',
'Row 1':'Reihe 1 ',
'Row 2':'Reihe 2 ',
'Row 3':'Reihe 3 ',
'Row 4':'Reihe 4 ',
'Row 5':'Reihe 5 ',
'Row 6':'Reihe 6 ',
'Row 7':'Reihe 7 ',
'Row 8':'Reihe 8 ',
'Row 9':'Reihe 9 ',
'Row 10':'Reihe 10 ',
'Row 11':'Reihe 11 ',
'Row 12':'Reihe 12 ',
'Row 13':'Reihe 13 ',
'Row 14':'Reihe 14 ',
'Row 15':'Reihe 15 ',
'Row 16':'Reihe 16 ',
'Row 17':'Reihe 17 ',
'Row 18':'Reihe 18 ',
'Row 19':'Reihe 19 ',
'Row 20':'Reihe 20 ',
'Row1':'Reihe 1 ',
'Row2':'Reihe 2 ',
'Row3':'Reihe 3 ',
'Row4':'Reihe 4 ',
'Row5':'Reihe 5 ',
'Row6':'Reihe 6 ',
'Row7':'Reihe 7 ',
'Row8':'Reihe 8 ',
'Row9':'Reihe 9 ',
'Row10':'Reihe 10 ',
'Row11':'Reihe 11 ',
'Row12':'Reihe 12 ',
'Row13':'Reihe 13 ',
'Row14':'Reihe 14 ',
'Row15':'Reihe 15 ',
'Row16':'Reihe 16 ',
'Row17':'Reihe 17 ',
'Row18':'Reihe 18 ',
'Row19':'Reihe 19 ',
'Row20':'Reihe 20 ',
'Row 1':'Reihe 1 ',
'Row 1:':'Reihe 1 ',
'Row2:':'Reihe 2 ',
'Row3:':'Reihe 3 ',
'Row4:':'Reihe 4 ',
'Row5:':'Reihe 5 ',
'Row6:':'Reihe 6 ',
'Row7:':'Reihe 7 ',
'Row8:':'Reihe 8 ',
'Row9:':'Reihe 9 ',
'Row10:':'Reihe 10 ',
'Row11:':'Reihe 11 ',
'Row12:':'Reihe 12 ',
'Row13:':'Reihe 13 ',
'Row14:':'Reihe 14 ',
'Row15:':'Reihe 15 ',
'Row16:':'Reihe 16 ',
'Row17:':'Reihe 17 ',
'Row18:':'Reihe 18 ',
'Row19:':'Reihe 19 ',
'Row20:':'Reihe 20 ',
'Stuff the arms from time to time, not very tightly':'Fülle die Arme von Zeit zu Zeit, nicht sehr fest',
'Fix and leave the thread to sew the arms to the body.':'Abbinden und einen Faden zum Annähen lassen.',
}
pattern = re.compile(r'\b(' + '|'.join(translation_table.keys()) +r')\b')
result = pattern.sub(lambda x : translation_table[x.group()], text)