Skip to content

Instantly share code, notes, and snippets.

@belkarx
Created February 8, 2023 05:24
Show Gist options
  • Select an option

  • Save belkarx/ba91dfdca1b11c91dd37a609c8124a38 to your computer and use it in GitHub Desktop.

Select an option

Save belkarx/ba91dfdca1b11c91dd37a609c8124a38 to your computer and use it in GitHub Desktop.
Text box that pops up and logs user input to file
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()
@belkarx

belkarx commented Feb 8, 2023

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment