Creating an Employee Punch Clock I'm trying to create a way to clock in and clock out at work using python and tkinter. There are several features to be implemented. 


Change the Employee Name
Clock In button
Clock Out button 
Export file with the information 


I have all the components and they work when I run the different features individually. When I try to combine to one script, the program fails. 

import tkinter as tk
import time

class StopWatch(Frame):  
    """ Implements a stop watch frame widget. """                                                                
    def __init__(self, parent=None, **kw):        
       Frame.__init__(self, parent, kw)
    self._start = 0.0        
    self._elapsedtime = 0.0
    self._running = 0
    self.timestr = StringVar()               
    self.makeWidgets()  

    def makeWidgets(self):                         
        """ Make the time label. """
        l = Label(self, textvariable=self.timestr)
        self._setTime(self._elapsedtime)
        l.pack(fill=X, expand=NO, pady=2, padx=2)                      

    def _update(self): 
        """ Update the label with elapsed time. """
        self._elapsedtime = time.time() - self._start
        self._setTime(self._elapsedtime)
        self._timer = self.after(50, self._update)

    def _setTime(self, elap):
        """ Set the time string to Minutes:Seconds:Hundreths """
        minutes = int(elap/60)
        seconds = int(elap - minutes*60.0)
        hseconds = int((elap - minutes*60.0 - seconds)*100)                
        self.timestr.set('%02d:%02d:%02d' % (minutes, seconds, hseconds))

    def Start(self):                                                     
        """ Start the stopwatch, ignore if running. """
        if not self._running:            
            self._start = time.time() - self._elapsedtime
            self._update()
            self._running = 1        

    def Stop(self):                                    
        """ Stop the stopwatch, ignore if stopped. """
        if self._running:
            self.after_cancel(self._timer)            
            self._elapsedtime = time.time() - self._start    
            self._setTime(self._elapsedtime)
            self._running = 0

    def Reset(self):                                  
        """ Reset the stopwatch. """
        self._start = time.time()         
        self._elapsedtime = 0.0    
        self._setTime(self._elapsedtime)

    def clock_in(self):
        global e1              
        data = e1.get()
        ClockIn_time = datetime.datetime.now()
        ClockIn_date = datetime.datetime.now().strftime('%Y-%m-%d')
        totalinput = [ data, ClockIn_time, ClockIn_date] 
        with open(r"C:\Users\Desktop\ClockIn.csv", "a") as savedb:
            w = csv.writer(savedb)
            w.writerow(totalinput)

    def clock_out(self):
        global e1              
        data = e1.get()
        ClockOut_time = datetime.datetime.now()
        ClockOut_date = datetime.datetime.now().strftime('%Y-%m-%d')
        totalinput = [ data, ClockOut_time , ClockOut_date ] 
        with open(r"C:\Users\Desktop\ClockIn.csv", "a") as savedb:
            w = csv.writer(savedb)
            w.writerow(totalinput)

def main():
    root = Tk()
    sw = StopWatch(root)
    sw.pack(side=TOP)
    root.geometry("400x400")

    ####
    label = tk.Label(root, text="Employee Name: ")
    label.pack(side="top")

    new = StringVar()
    e1 = Entry(root, textvariable=new)
    e1.pack()
    #######

    Button(root, text='Clock In', command=lambda :[sw.Start(), sw.clock_in()]).pack(side=LEFT)
    Button(root, text='Clock Out', command=lambda :[sw.Start(), sw.clock_out()]).pack(side=LEFT)
    Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
    Button(root, text='Quit', command=root.quit).pack(side=LEFT)

    root.mainloop()

if __name__ == '__main__':
    main()


I'm having trouble get() the employees name and saving to a file. I've created a stand alone tkinter app, I'm able to do this, when I implement multiple features I cannot get them all to marinate.
Incorrect indention

All of the methods in a class need to be indented such that they are inside the class definition. (this is based on the original version of the code you posted.

Instead of this:

 class StopWatch(Frame):  
   """ Implements a stop watch frame widget. """                                                                
   def __init__(self, parent=None, **kw): ...

def makeWidgets(self): ...                        
def _update(self): ...
def _setTime(self, elap): ...
def Start(self): ...                                                  
def Stop(self): ...                                  
def Reset(self): ...                                 
def clock_in(self): ...
def clock_out(self): ...


You need to do this:

class StopWatch(Frame):  
   """ Implements a stop watch frame widget. """                                                                
    def __init__(self, parent=None, **kw): ...

    def makeWidgets(self): ...                        
    def _update(self): ...
    def _setTime(self, elap): ...
    def Start(self): ...                                                  
    def Stop(self): ...                                  
    def Reset(self): ...                                 
    def clock_in(self): ...
    def clock_out(self): ...


Follow PEP8 Guidelines

PEP8 gives guidelines that every python program should follow. Specifically in your case, function names need to begin with a lowercase character.

StringVar is unnecessary overhead

In most cases, using StringVar adds overhead with no real value. While this is more of a personal preference, I see no reason to use it. StringVar objects are good if you want the exact same value displayed in two or more widgets, or if you're wanting to trace changes. Otherwise they are superfluous. 

Instead of self.timestr, you can directly alter the widget value. So, instead of saving a reference to the StringVar, save a reference to the widget:

def makeWidgets(self): 
    ...                        
    self.time_label = Label(self, textvariable=self.timestr)
    ...  

def _setTime(self, elap):
    ...           
    self.time_label.configure(text='%02d:%02d:%02d' % (minutes, seconds, hseconds))
    ...


Be consistent with private methods

By convention, private methods (methods that are only used internally) are named with a leading underscore. You do this with _update and _setTime, but you didn't do it with makeWidgets. You should try to be consistent: if a function is only used internally, name it with a leading underscore. 

Don't hard-code the filename

Your program would be a bit more portable if you didn't hard-code the filename. Right now you have the filename hard-coded in the clock_in and clock_out functions. 

Instead, make it a parameter when you instantiate the class, or make it global.

For example:

def clock_in(self):
    ...
    with open(self.filename, "a") as savedb:
    ...

def clock_out(self):
    ...
    with open(self.filename, "a") as savedb:
    ...
sw = StopWatch(root, filename=r"C:\Users\Desktop\ClockIn.csv")


Separate widget creation from widget layout

In my experience, separating widget creation makes the code easier to visualize and easier to maintain. 

Instead of this:

Button(root, text='Clock In', command=lambda :[sw.Start(), sw.clock_in()]).pack(side=LEFT)
Button(root, text='Clock Out', command=lambda :[sw.Start(), sw.clock_out()]).pack(side=LEFT)
Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
Button(root, text='Quit', command=root.quit).pack(side=LEFT)


... do this:

clock_in_button = Button(...)
clock_out_button = Button(...)
reset_button = Button(...)
quit_button = Button(...)

clock_in_button.pack(side=LEFT)
clock_out_button.pack(side=LEFT)
reset_button.pack(side=LEFT)
quit_button.pack(side=LEFT)


This makes it much more clear to see at a glance that all for buttons are aligned to the left. When it's all blocked together it's much harder to see.

Incorrect use of tkinter

You're importing tkinter with import tkinter as tk but then trying to use tk classes without the tk. prefix.

The import is good, but you need to fix all of the code that is creating widgets. For example, tk.Button(...) instead of just `Button(...).