-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated GUI - GUI Improvisation - Increased the size of Diary Entry area to enhance visibility while typing and making it convenient to edit errors. - Automatically acquires Date from system. No need to type date as in OG version.
- Loading branch information
1 parent
7234a4d
commit 577580e
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# This is a python code to create a program to enter daily diary and save it as .txt file | ||
# The program also has a basic GUI using PySimpleGUI | ||
# The program gets the current date from the system and asks the user for the content of the diary entry | ||
# The program then creates a file with the current date as the name and writes the content to it | ||
# The program also checks if the file already exists and asks the user if they want to overwrite it or append to it | ||
# Import the os module to check if the file exists | ||
import os | ||
# Import PySimpleGUI to create the GUI | ||
import PySimpleGUI as sg | ||
# Import the datetime module to get the current date | ||
from datetime import datetime | ||
# Get the current date | ||
current_date = datetime.now().strftime("%Y-%m-%d") | ||
# Define the layout of the GUI | ||
layout = [ | ||
[sg.Text(f"Date: {current_date}")], | ||
[sg.Text("Enter your diary entry:")], | ||
[sg.Multiline(key="-CONTENT-", size=(40, 10))], | ||
[sg.Button("Save"), sg.Button("Exit")] | ||
] | ||
# Create the window with the layout | ||
window = sg.Window("Diary", layout) | ||
# Loop through the events and values of the window | ||
while True: | ||
event, values = window.read() | ||
# If the user clicks Exit or closes the window, break the loop | ||
if event == "Exit" or event == sg.WIN_CLOSED: | ||
break | ||
# If the user clicks Save, get the content from the values | ||
if event == "Save": | ||
content = values["-CONTENT-"] | ||
# Create the file name with the current date and .txt extension | ||
file_name = current_date + ".txt" | ||
# Check if the file already exists | ||
if os.path.exists(file_name): | ||
# Ask the user if they want to overwrite or append | ||
choice = sg.popup_yes_no("The file already exists. Do you want to overwrite (Yes) or append (No)?") | ||
# If the user chooses to overwrite | ||
if choice == "Yes": | ||
# Open the file in write mode and write the content | ||
with open(file_name, "w") as f: | ||
f.write(content) | ||
# Show a confirmation message | ||
sg.popup("The file has been overwritten.") | ||
# If the user chooses to append | ||
elif choice == "No": | ||
# Open the file in append mode and write the content | ||
with open(file_name, "a") as f: | ||
f.write("\n" + content) | ||
# Show a confirmation message | ||
sg.popup("The file has been appended.") | ||
# If the user cancels, do nothing | ||
else: | ||
pass | ||
# If the file does not exist | ||
else: | ||
# Open the file in write mode and write the content | ||
with open(file_name, "w") as f: | ||
f.write(content) | ||
# Show a confirmation message | ||
sg.popup("The file has been created.") | ||
# Close the window | ||
window.close() |