#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Clock Time Module Problem


    Okay Here is my script it works fine and all:

    Code:
    import time
    from Tkinter import *
    
    root = Tk()
    root.title("Clock")
    
    StartVal = time.localtime(time.time())
    sth = time.strftime("%H",StartVal)
    stm = time.strftime("%M",StartVal)
    sts = time.strftime("%S",StartVal)
    
    Timestamp = StringVar(root)
    Timestamp.set(time.strftime('%H:%M:%S\n%d:%m:%Y', time.localtime()))
    
    Init = StringVar(root)
    Init.set("0:0:0")
    
    Label(root,text="Current Time:").pack()
    Label(root,textvariable=Timestamp).pack()
    
    Label(root,text="Time Since Process Start").pack()
    Label(root,textvariable=Init).pack()
    
    def TimeSince():
        EndVal = time.localtime(time.time())
        enh = time.strftime("%H",EndVal)
        enm = time.strftime("%M",EndVal)
        ens = time.strftime("%S",EndVal)
        ENDH = int(enh)-int(sth)
        ENDM = int(enm)-int(stm)
        ENDS = int(ens)-int(sts)
        if ENDH < 0:
        	ENDH = 0
        if ENDM < 0:
        	ENDM = ENDM+60
        if ENDS < 0:
        	ENDS = ENDS+60
        Init.set("%i:%i:%i" % (ENDH,ENDM,ENDS))
    
    def T():
        while True:
            Timestamp.set(time.strftime('%H:%M:%S\n%d:%m:%Y', time.localtime()))
            TimeSince()
            try: root.update()
            except: return
    
    root.after(1,T)
    root.mainloop()
    It is not the best design and all that...

    But there is a bug in it when on the current time one minute goes past one minute is recoded on the one which counts how long since the program started...

    for example

    Current Time:
    22:39:25
    31:07:2005
    Time Since Process Start
    0:0:39

    the the minute on the upper clock goes on an other one then the lower one also switches a minute:

    Current Time:
    22:40:01
    31:07:2005
    Time Since Process Start
    0:1:47

    ...

    Whats wrong I can't find the error and if there is an easier way to do the whole second thing please tell me...

    I have gone mad about this...
    Those people who think they know everything are a great annoyance to those of us who do.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I'm still a bit confused. Can you tell me what your program should be doing?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Code:
    ENDM = int(enm)-int(stm)
    Lets say, you start you program at 0:0:30. stm = 0. After 30 seconds, we have 0:1:0. stm is still 0, but enm = 1 => ENDM = 1!
    Why don't you just count the seconds, and after 60 seconds ENDM += 1 and after 3600 seconds ENDH += 1.
    Also you don't have to call time.whatever() every second. Just call it once at the beginning, then increase the seconds every second

    Regards, mawe
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    okay well ill try to redesign it and it is not that important anyways
    Those people who think they know everything are a great annoyance to those of us who do.

IMN logo majestic logo threadwatch logo seochat tools logo