MemoBox Project

Have you ever needed to write down an important piece of information, but couldn’t find any paper? Well, I wrote a program for this! MemoBox is a desktop application that automatically writes memos to a file. The app is easy to use as all one has to do is enter text into the entry box and press “Write.” The program writes the memo to a file and then sorted by year, month, and day.

Process

Python comes with a Graphical User Interface (GUI) builder called Tkinter (Tk Interface). I discovered tkinter while searching online for information regarding Python desktop application development. After learning the basics of the package, I set out to create a few desktop apps.

The first app I attempted was a calculator. I had already built a console calculator and thought I could enhance it with a GUI. This was a bad idea! I ran into a plethora of problems as I attempted to merge my already-existing code with tkinter. I didn’t realize that when front-end development is concerned, functions need to be written in a way that allows for easy front-end code implementation!

After this debacle, I set out to develop another desktop app that would record various pieces of information; I called this app MemoBox.

MemoBox Development

Before typing a single line of code, I reviewed the development process. By doing this, it allowed me to gauge where problems might arise. For example, I knew that I would have a hard time combining the tkinter class app with the back-end I/O. As suspected, this was the hardest portion to code!

Once I implemented the file writing feature on the GUI, I decided to enhance it. First, I added a dash to each memo entry as to make the file more presentable (shown below).
Second, there needed to be an easy way to open the file a user has written to. So, I created a button on the GUI, called “Open”, that linked to a function that opened the project’s root directory in explorer.

As of this writing, the open file feature only fully works if a user changes the variable ‘path_open’ in main.py (line 29) to the path the user has set for the project. If the user doesn’t change the variable, explorer will still pop up, but not in the project’s root directory. I could not come up with better code to fix this and I hope to fix this in the future.

Code Snippet

I would like to review the function that writes the user’s memos to a file. After the user writes a memo and presses the “Write” button, the below function is called:

def write_memo(entry, date, month, path):
    text = entry.get()
    date_str = "{}-{}-{}.txt".format(month, date.day, date.year)
    write_template = "- "            # Creates a 'list' in file.
    create_dir(path)

    with open(path + date_str, "a") as f:
        f.write(write_template + text + "\n")

    entry.delete(first=0, last=139)  # Deletes text in Entry widget.

This function first calls the another function, called create_dir(), which attempts to create the directories that separate each memo file. The write_memo function then writes the user’s memo to a file nested within the directories (shown on the right). What was interesting was that after the user pressed the “Write” button, the entry box didn’t clear. To fix this, I added entry.delete() which deletes the text in the entry box so that the user can write another memo.

Overall

I am quite happy with the outcome of this project. The program had been written so that it can be improved upon in the future. I learned about tkinter and how to combine back-end and front-end code. Going forward, I hope to create more elaborate desktop applications.


Check out MemoBox for yourself as I want to hear your thoughts on the project! Any questions, comments, or concerns you may have can be posted in the comments section below.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments