91 lines
2.6 KiB
Python
Executable File
91 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import tkinter as tk
|
|
from tkinter import ttk, StringVar
|
|
from tkinter.messagebox import showinfo
|
|
from datetime import datetime
|
|
|
|
now = datetime.now()
|
|
YEAR = now.strftime("%Y")
|
|
MONTH = now.strftime("%m")
|
|
DAY = now.strftime("%d")
|
|
journal_filename = "%s-%s-%s-Journal.txt" % (YEAR, MONTH, DAY)
|
|
|
|
# determine OS to correctly save journal file and to switch back to one-branch development for convenience
|
|
if os.name == 'posix':
|
|
journal_filename_path = "./%s" % journal_filename
|
|
|
|
if os.name == 'nt':
|
|
journal_filename_path = "$Env:AppData/%s" % journal_filename
|
|
|
|
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()
|
|
# set Window to fullscreen (dependend of the actual screensize)
|
|
width = journal.winfo_screenwidth()
|
|
height = journal.winfo_screenheight()
|
|
journal.geometry("%dx%d" % (width, height))
|
|
journal.title("Ameland Kinderjournal")
|
|
|
|
# store name and message
|
|
name = tk.StringVar()
|
|
message = tk.StringVar()
|
|
|
|
# Main Window
|
|
journal = ttk.Frame(journal)
|
|
journal.pack()
|
|
|
|
# name
|
|
name_label = ttk.Label(journal, text = "Dein Name:")
|
|
name_label.pack(fill = 'x', expand = True)
|
|
name_entry = ttk.Entry(journal, textvariable = name)
|
|
name_entry.pack(fill = 'x', expand = True)
|
|
name_entry.focus()
|
|
|
|
# textbox
|
|
message_label = tk.Label(journal, text = "Deine Nachricht:")
|
|
message_label.pack(fill = 'x', expand = True)
|
|
message_text = tk.Text(journal, height = 50)
|
|
message_text.pack()
|
|
|
|
|
|
def send_button_clicked():
|
|
with open(journal_filename_path, "a") as journal_of_the_day:
|
|
journal_of_the_day.write("Eintrag von: " + name.get() + " um " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n")
|
|
journal_of_the_day.write(message_text.get(1.0, "end-1c") + "\n")
|
|
journal_of_the_day.write("-----------------\n")
|
|
message_text.delete('1.0', "end-1c")
|
|
name.set("")
|
|
showinfo(title = "Information", message = "Deine Nachricht wurde gespeichert")
|
|
|
|
def save_and_quit_button_clicked():
|
|
with open(journal_filename_path, "a") as journal_of_the_day:
|
|
journal_of_the_day.write(name.get() + "\n")
|
|
journal_of_the_day.write(message_text.get(1.0, "end-1c") + "\n")
|
|
journal_of_the_day.write("-----------------\n")
|
|
journal.quit()
|
|
|
|
# Send Button
|
|
button_send = ttk.Button(
|
|
journal,
|
|
text = "Abschicken",
|
|
command = lambda: send_button_clicked()
|
|
)
|
|
button_send.pack(pady = 15, padx = 15)
|
|
|
|
# Quit Button
|
|
button_quit = ttk.Button(
|
|
journal,
|
|
text = "Speichern und Beenden",
|
|
command = lambda: save_and_quit_button_clicked()
|
|
)
|
|
button_quit.pack()
|
|
|
|
journal.mainloop() |