Hello all, trying to get my program working. The program is to take input from the user in a hh:mmx format (x being p or a, standing for PM and AM) and tell the user how many minutes from midnight that time is. I was able to make it so it would work in the Shell using the following code snippet:

def timedif(x):
    h = int(x[0:2])
    m = int(x[3:5])
    ampm = n[-1]
    if h != 12 and ampm == 'p':
        h = h + 12
    time = h*60 + m
    print time
n = raw_input('Input a time in hh:mmx format: ')
timedif(n)

Now I am trying to make it work in a Tkinter format. The following snippet is what I have so far. Wondering if you all could help me figure out how to get it working. Thanks!

import Tkinter

win = Tkinter.Tk()
win.title('Time Clock')
class Converter():
    def __init__ (self,x):
        self.x = x
    def convert(self,x):
        h = int(x[0:2])
        m = int(x[3:5])
        ampm = n[-1]
        if h != 12 and ampm == 'p':
            h = h + 12
        diff = h*60 + m
conv = Converter(5)    



label = Tkinter.Label(win,text="Calculate Elapsed Time in Minutes",font=('Courier New',32,'bold'))
label.pack()

Row3 = Tkinter.Frame(win)
mLabel = Tkinter.Label(Row3,text = "Enter Time (hh:mmx) With x = a or p",font=('Courier New',30))
mEntry = Tkinter.Entry(Row3,width=6,font=('Courier New',30))
mLabel.pack(side='left')
mEntry.pack(side='right')
Row3.pack()

Row4 = Tkinter.Frame(win)
vLabel = Tkinter.Label(Row4,text="Elapsed Minutes Since Midnight",font=('Courier New',30))
vLabel.pack()
Row4.pack()

Row5 = Tkinter.Frame(win)
qb = Tkinter.Button(Row5,text='Quit',command=win.destroy,font=('Courier New',30))
cb = Tkinter.Button(Row5,text='Convert',font=('Courier New',30))
qb.pack(side='left')
cb.pack(side='right')
Row5.pack()
win.mainloop()

I was wondering why you weren't using the Time class out of the datetime module. It correctly handles a lot of what you are doing manually right now.

You should send the time value entered to the class, so this statement should be in a function that is called when the "Convert" button is pressed
conv = Converter(5)
and should send the value from the Entry instead of "5" (links to using get to read an entry and callbacks for a button click

Next the class uses "n" which it doesn't have access to
ampm = n[-1]
You should be using "x" or even better self.x

The "Elapsed Minutes Since Midnight" should actually show something which requires a Tkinter variable

Finally you should allow for 2:2P instead of 02:02P which means you should split on the colon instead of the [0:2] and [3:5] slices

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.