#!/glimmer/bin/python3 '''Ravi Chande CSC 323 Logger.py: defines a very simple logging program that will write text to predefined (but mutable) logfile. Adapted heavily from "Whoops! Setting up tkinter", an email from Sam Rebelsky ''' import tkinter, os from datetime import datetime def write(string): '''open the logfile, and write the current time and the string''' print("Writing the file") #replace the parameter to expanduser to set the log file handle = open(os.path.expanduser("~/.323log"), "a") handle.write('\n') handle.write('\t'.join([datetime.now().isoformat(), string])) handle.write('\n') handle.close() class workbutton: '''workbutton: constructed with a name and a work type, which are allowed to be equivalent. It will be labeled with name and prints its work type when write() is called''' def __init__(self, parent, name, work): self.parent = parent self.name = name self.work = work self.button = tkinter.Button(parent, text=name) #use a fancy lambda in the bind self.button.bind("", lambda s:write(self.work)) self.button.pack() class logger: '''uses its constructor to initialize a frame and some buttons''' def __init__(self, parent): self.frame = tkinter.Frame(parent, width=200, height=100) self.frame.pack() work = ['Explanation', 'Design', 'Planning', 'Documentation',\ 'Resources', 'Testing', 'Coding', 'Debugging', 'Overhead'] for w in work: workbutton(self.frame, w, w) workbutton(self.frame, 'Magic', '''\n\nMagic\n\n''') workbutton(self.frame, 'Done!', '''\n\n======Done======\n\n''') root = tkinter.Tk() logger(root) root.mainloop()