Created
February 8, 2023 05:24
-
-
Save belkarx/ba91dfdca1b11c91dd37a609c8124a38 to your computer and use it in GitHub Desktop.
Text box that pops up and logs user input to file
This file contains hidden or 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
| import tkinter as tk | |
| from datetime import datetime | |
| timestamp = datetime.now().strftime("%m-%d %H:%M:%S") | |
| f = open("doinglog.txt", "a") | |
| def submit_text(event=None): | |
| text = text_var.get() | |
| print(text) | |
| root.destroy() | |
| root = tk.Tk() | |
| root.eval('tk::PlaceWindow . center') | |
| text_var = tk.StringVar() | |
| entry = tk.Entry(root, textvariable=text_var) | |
| entry.focus() | |
| entry.bind("<Return>", submit_text) | |
| entry.pack() | |
| root.mainloop() | |
| f.write(f"{timestamp} | {text_var.get()}\n") | |
| f.close() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is intended to be used with a cronjob as a productivity tool to guilt the user into actually accomplishing things by forcing low-friction logs of activities.
cronjob:
0 */2 * * * DISPLAY=$(w $(id -un) | awk 'NF > 7 && $2 ~ /tty[0-9]+/ {print $3; exit}') /bin/python3 /home/uk000/tk.py