On Tue, 11 Apr 2006 18:02:37 +0200 (Central European Daylight Time)
"Aleksandar Cikota" <[EMAIL PROTECTED]> wrote:

>  Hello,
> 
> I'm writing a software for our future robotic telescope in Python and
> started to make the GUI.
> I'm beginner in Tkiner and have a easy question. How to refresh this loop
> (and print the time) every 
> second?
> 
> 
> 
> Here the code:
> 
> 
> from Tkinter import *
> import win32com.client
> Scope = win32com.client.dynamic.Dispatch('ScopeSim.Telescope')
> root=Tk()
> 
> Label(root, text=Scope.SiderealTime).grid(row=0, sticky=W)
> 
> root.mainloop()
> 
> 
> -----
> Scope.SiderealTime is LST from a telescope simulator, but it is only an
> exemple. You can also use system time for explaining.
> 

Hi Aleksandar,

the easiest way is to define a callback and use after() to periodically invoke 
it:

from Tkinter import *
import win32com.client
Scope = win32com.client.dynamic.Dispatch('ScopeSim.Telescope')
root=Tk()
label = Label(root, text=Scope.SiderealTime)
label.grid(row=0, sticky=W)

def update_label():
    label.config(text=Scope.SiderealTime)
    label.after(1000, update_label)

label.after(1000, update_label)

The time after which the next call to update_label() occurs (1000 ms here) is 
not exact however,
so the interval to be used depends on your needs; I have used an interval of 
250 ms for a
"digital clock" widget that displays full seconds and it looks good enough to 
me, but if you look close
you may find that some "second" takes longer than the others.

HTH

Michael

_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to