From a604b4d201e527fa1c29c132c050fe5220482132 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 20 Jan 2024 00:01:35 +0100 Subject: [PATCH] =?UTF-8?q?wir=20k=C3=B6nnen=20eine=20Datei=20erstellen,?= =?UTF-8?q?=20falls=20ben=C3=B6tigt=20und=20reinschreiben=20und=20anf?= =?UTF-8?q?=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- journal.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/journal.py b/journal.py index 6448673..ca5c2c0 100755 --- a/journal.py +++ b/journal.py @@ -2,7 +2,7 @@ import tkinter as tk import os -from tkinter import ttk +from tkinter import ttk, StringVar from tkinter.messagebox import showinfo from datetime import datetime @@ -13,11 +13,10 @@ DAY = now.strftime("%d") journal_filename = "%s-%s-%s-Journal.txt" %(YEAR, MONTH, DAY) journal_filename_path = "./%s" % journal_filename -#if os.path.exists(journal_filename_path): -# print('file already exists') -#else: -# # create a file -# with open(journal_filename_path) +if not os.path.exists(journal_filename_path): + with open(journal_filename_path, "w"): pass +else: + with open(journal_filename_path, "a"): pass # configure root window journal = tk.Tk() @@ -48,11 +47,19 @@ message_label.pack(fill='x', expand=True) message_text = tk.Text(journal, height=50) message_text.pack() +def send_button_clicked(name, message): + with open(journal_filename_path, "a") as journal_of_the_day: + journal_of_the_day.write(name.get()) + journal_of_the_day.write(message.get()) + journal_of_the_day.write("-----------------") + showinfo(title="Information", message="Deine Nachricht wurde gespeichert") + # Send Button button_send = ttk.Button( journal, text="Abschicken", - command=lambda: showinfo(title="Information", message="Deine Nachricht wurde gespeichert") + #command=lambda: showinfo(title="Information", message="Deine Nachricht wurde gespeichert") + command=send_button_clicked(name, message) ) button_send.pack()