How to create a timetracker?
Question: I'm very new to Python. I want to create a script for time tracking with a
grafical interface. Once you hit start the start time should be stored and
when you hit stop the time difference shoult be displayed.

This is my approach to the topic:

    
    
    import datetime
    from Tkinter import *
    
    root=Tk()
    
    def starttime():
        start=datetime.datetime.now()
        print start
    
    def stoptime():
        stop=datetime.datetime.now()
        print stop
        delta=stop-start
        print delta
    
    startb = Button(root, text="Start", command=starttime)
    startb.pack()
    stopb = Button(root, text="Stop", command=stoptime)
    stopb.pack()
    
    mainloop()
    

Thanks for any help to this noob ;).


Answer: Since `start` is a local variable, its value is forgotten when the `starttime`
function ends. If you want it to persist you can make it a global variable

    
    
    def starttime():
        global start
        start=datetime.datetime.now()
        print start
    

You should probably at some time read up about why there are local and global
variables, and how to avoid using globals too often.

