OK, here is a litting script I wrote (admittedly with some help from http://www.pythonware.com/library/tkinter/introduction/hello-again.htm)that will allow me to cloak in with ease here at work. Only.... since I sometimes log into the computer multiple times in the day, I wanted to use Tkinter to give me a yes/no button. But.... I was having trouble getting it to close the tkinter box afterwards. If I select "Don't clock in", the button is depressed, but the box is still there, and I have to end it manually. I'm still a bit cloudy about some of the things that are happening in the program, but I can't see why it doesn't work quite right.

# File: clockin.py

from Tkinter import *
from win32com.client import Dispatch
import time

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()

self.button = Button(frame, text="Don't clock in", command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text="Clock in", command=self.clock_in)
self.hi_there.pack(side=LEFT)

def clock_in(self):
xlApp = Dispatch("Excel.Application")
logfile = r"h:\hourslog.xlsx"
date = time.strftime("%a %m/%d/%y", time.localtime())
r = 1

xlApp.Workbooks.Open(logfile)

while True:
if xlApp.ActiveWorkbook.ActiveSheet.Cells(r,1).Value == None:
xlApp.ActiveWorkbook.ActiveSheet.Cells(r,1).Value = date
xlApp.ActiveWorkbook.ActiveSheet.Cells(r,2).Value = time.strftime("%H:%M:%S", time.localtime())
break
elif xlApp.ActiveWorkbook.ActiveSheet.Cells(r,1).Value == date:
xlApp.ActiveWorkbook.ActiveSheet.Cells(r,3).Value = time.strftime("%H:%M:%S", time.localtime())
break
else:
r = r + 1

xlApp.ActiveWorkbook.Save()
xlApp.ActiveWorkbook.Close(SaveChanges=1)
#xlApp.Quit()
#xlApp.Visible = 0
self.quit

root = Tk()

app = App(root)

root.mainloop()

Nevemind, found the issue myself after playing around with it even more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.