import subprocess
from tkinter import *
# Dictionary mit Abkürzungen und ihren entsprechenden Texten
abbreviations = {
"mfg": "Mit freundlichen Grüßen",
"btw": "By the way",
# Fügen Sie weitere Abkürzungen hinzu, falls nötig
}
def addText():
text_to_add = message.get()
T.insert(END, text_to_add + "\n")
message.delete(0, END)
def saveText():
text_to_save = T.get("1.0", END)
with open("saved_text.txt", "w") as file:
file.write(text_to_save)
def loadText():
try:
with open("saved_text.txt", "r") as file:
saved_text = file.read()
T.delete("1.0", END)
T.insert(END, saved_text)
except FileNotFoundError:
print("Es wurde noch kein Text gespeichert.")
def copyToClipboard():
selected_text = T.selection_get()
root.clipboard_clear()
root.clipboard_append(selected_text)
root.update()
def insertAbbreviation(abbreviation):
if abbreviation in abbreviations:
T.insert(END, abbreviations[abbreviation] + "\n")
def copyMfGToApplication():
text_to_insert = "Mit freundlichen Grüßen"
# Kopiere Text in Zwischenablage
root.clipboard_clear()
root.clipboard_append(text_to_insert)
root.update()
# Füge den Text in die aktive Anwendung ein
subprocess.run(["xdotool", "key", "Ctrl+v"])
root = Tk()
root.title("Typeitin")
root.geometry('450x600')
T = Text(root, height=10, width=40)
T.pack()
message = Entry(root, width=30)
message.pack()
add_button = Button(root, text="Text hinzufügen", command=addText)
add_button.pack()
save_button = Button(root, text="Text speichern", command=saveText)
save_button.pack()
load_button = Button(root, text="Text laden", command=loadText)
load_button.pack()
copy_button = Button(root, text="Kopieren", command=copyToClipboard)
copy_button.pack()
# Erstellen Sie Buttons für Abkürzungen
for abbreviation in abbreviations:
abbrev_button = Button(root, text=abbreviation, command=lambda ab=abbreviation: insertAbbreviation(ab))
abbrev_button.pack()
copy_to_app_button = Button(root, text="mfG in Anwendung einfügen", command=copyMfGToApplication)
copy_to_app_button.pack()
root.mainloop()