Compare commits

..

No commits in common. "681f9b11630b1337652b8ba7dc9990bb631fea84" and "19a0e6000d0b488e96ad0d6dbe4301b456e515c3" have entirely different histories.

View File

@ -13,7 +13,6 @@ MONTH = now.strftime("%m")
DAY = now.strftime("%d") DAY = now.strftime("%d")
journal_filename = "%s-%s-%s-Journal.txt" % (YEAR, MONTH, DAY) 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 # determine OS to correctly save journal file and to switch back to one-branch development for convenience
if os.name == 'posix': if os.name == 'posix':
journal_filename_path = "./%s" % journal_filename journal_filename_path = "./%s" % journal_filename
@ -28,10 +27,11 @@ else:
with open(journal_filename_path, "a"): with open(journal_filename_path, "a"):
pass pass
# configure root window
journal = tk.Tk() journal = tk.Tk()
journal.attributes('-alpha', 0.5) # label = tk.Label(journal, image=image)
# label.place(x=0, y=0)
#
# set window to fullscreen (dependend of the actual screensize) and fill with a background image # set window to fullscreen (dependend of the actual screensize) and fill with a background image
image_location = 'background.jpg' image_location = 'background.jpg'
width = journal.winfo_screenwidth() width = journal.winfo_screenwidth()
@ -41,46 +41,32 @@ journal.title("Ameland Kinderjournal")
img = ImageTk.PhotoImage(Image.open(image_location).resize((width, height), Image.ADAPTIVE)) img = ImageTk.PhotoImage(Image.open(image_location).resize((width, height), Image.ADAPTIVE))
label = tk.Label(journal, image=img) label = tk.Label(journal, image=img)
# Keep a reference in case this code put is in a function.
#
# Keep a reference in case this code is put in a function.
label.img = img label.img = img
#
# Place label in center of parent. # Place label in center of parent.
label.place(relx=0.5, rely=0.5, anchor='center') label.place(relx=0.5, rely=0.5, anchor='center')
#
# store name and message # store name and message
name = tk.StringVar() name = tk.StringVar()
message = tk.StringVar() message = tk.StringVar()
#
# Main Window # Main Window
journal = ttk.Frame(journal) journal = ttk.Frame(journal)
journal.pack(pady=100, side=tk.TOP) journal.pack()
#
# name # name
name_label = ttk.Label(journal, text = "Dein Name:") name_label = ttk.Label(journal, text = "Dein Name:")
name_label.grid(sticky = 'w', column = 0, row = 0, padx = 5, pady = 5) name_label.pack(fill = 'x', expand = True)
name_entry = ttk.Entry(journal, textvariable = name, width = 70) name_entry = ttk.Entry(journal, textvariable = name)
name_entry.grid(sticky = 'e', column = 0, row = 0, padx = 90, pady = 5) name_entry.pack(fill = 'x', expand = True)
name_entry.focus() name_entry.focus()
#
# textbox # textbox
# TODO: textbox need a scrollbar when applicable
# standard height of the textbox is 40 unless the screen provides more space in which case we will compute
# the textbox_heigth reasonably and relatively to the screensize
textbox_height: int = 40
if height > 1080:
textbox_height = height - 1400
message_label = tk.Label(journal, text = "Deine Nachricht:") message_label = tk.Label(journal, text = "Deine Nachricht:")
message_label.grid(column = 0, row = 1, sticky = 'w', padx = 5) message_label.pack(fill = 'x', expand = True)
message_text = tk.Text(journal, height = textbox_height) message_text = tk.Text(journal, height = 50)
message_text.grid(column = 0, row = 2, padx = 5) message_text.pack()
def send_button_clicked(): def send_button_clicked():
with open(journal_filename_path, "a") as journal_of_the_day: with open(journal_filename_path, "a") as journal_of_the_day:
@ -96,28 +82,22 @@ def save_and_quit_button_clicked():
journal_of_the_day.write(name.get() + "\n") 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(message_text.get(1.0, "end-1c") + "\n")
journal_of_the_day.write("-----------------\n") journal_of_the_day.write("-----------------\n")
if not name.get():
journal_of_the_day.write("Speichern und Beenden von: " + "<noname>" + " um " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n")
else:
journal_of_the_day.write("Speichern und Beenden von: " + name.get() + " um " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n")
journal.quit() journal.quit()
#
# Send Button # Send Button
button_send = ttk.Button( button_send = ttk.Button(
journal, journal,
text = "Abschicken", text = "Abschicken",
command = lambda: send_button_clicked() command = lambda: send_button_clicked()
) )
button_send.grid(sticky = 'w', column = 0, row = 3, ipady = 8, padx = 5, pady = 5) button_send.pack(pady = 15, padx = 15)
#
# Quit Button # Quit Button
button_quit = ttk.Button( button_quit = ttk.Button(
journal, journal,
text = "Speichern und Beenden", text = "Speichern und Beenden",
command = lambda: save_and_quit_button_clicked() command = lambda: save_and_quit_button_clicked()
) )
button_quit.grid(sticky = 'e', column = 0, row = 3, ipady = 8, padx = 5, pady = 5) button_quit.pack()
journal.mainloop() journal.mainloop()