Updating a clock on a notepad tab
Question: I'm making an application through Python and one of the tabs I'm creating is
to show the current times: local and GMT. When I start the program, it gives
me the time at which the program was started. I was wondering if there was a
way to update the times so that I can have the actual time on the application.
I tried this type of code for my clocks:
<http://ygchan.blogspot.com/2012/05/python-how-to-make-clock-timer-in.html>

This is what I have for my application so far:

    
    
        from Tkinter import *
        from ttk import *
        import time
    
        root = Tk()
        root.geometry('1000x900')
        root.title("Astronomical Observing Recording Program")
        frame1 = Frame(root, name='frame1')
        frame1.pack(fill=BOTH)
    
    
        localtime = time.asctime(time.localtime(time.time()))
        gmttime = time.asctime(time.gmtime(time.time()))
    
        welcome_message = "Hi" #shortened
    
    
       current_time = "The current time is: " + str(localtime)
       gmt_time = "The current GMT time is: " + str(gmttime)
    
    
       root.protocol("WM_DELETE_WINDOW", frame1.quit)
       nb = Notebook(frame1, name='nb')
       nb.pack(fill=BOTH, padx=2, pady=3)
    
       welcome_screen = Frame(nb, name='welcome_screen')
       Label(welcome_screen, text=welcome_message).pack(side=LEFT)
       nb.add(welcome_screen, text='Welcome')
    
       time_screen = Frame(frame1, name='time_screen')
       Label(time_screen, text=current_time).pack(side=TOP)
       Label(time_screen, text=gmt_time).pack(side=TOP)
       nb.add(time_screen, text='Time Bar')
    
       frame1.mainloop()
    

It would be appreciated if someone could help me, or even set me in the right
direction so I could try to fix it myself.

Thanks


Answer: Use [after](http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.after-
method) which will call the function after given time.

    
    
    from Tkinter import *
    from ttk import *
    import time
    
    root = Tk()
    root.geometry('1000x900')
    root.title("Astronomical Observing Recording Program")
    frame1 = Frame(root, name='frame1')
    frame1.pack(fill=BOTH)
    
    
    welcome_message = "Hi" #shortened
    
    
    root.protocol("WM_DELETE_WINDOW", frame1.quit)
    nb = Notebook(frame1, name='nb')
    nb.pack(fill=BOTH, padx=2, pady=3)
    
    welcome_screen = Frame(nb, name='welcome_screen')
    Label(welcome_screen, text=welcome_message).pack(side=LEFT)
    nb.add(welcome_screen, text='Welcome')
    
    time_screen = Frame(frame1, name='time_screen')
    lb_current_time = Label(time_screen)
    lb_current_time.pack(side=TOP)
    lb_gmt_time = Label(time_screen)
    lb_gmt_time.pack(side=TOP)
    nb.add(time_screen, text='Time Bar')
    
    def update_time():
        localtime = time.asctime(time.localtime(time.time()))
        gmttime = time.asctime(time.gmtime(time.time()))
        current_time = "The current time is: " + localtime
        gmt_time = "The current GMT time is: " + gmttime
        lb_current_time['text'] = current_time
        lb_gmt_time['text'] = gmt_time
        root.after(1000, update_time)
    update_time()
    
    
    frame1.mainloop()
    

