Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to make an object that handles basic time related functions. I want it so when any of the attributes (e.g. self.Time ) are referenced they are up to date. However, for some reason wx.CallLater(1000, self.Tick) doesn't seem to be updating the attributes. It will only print self.Time once, as opposed to every second (like I want it to).

How would I go about getting the behavior I desire? Should I use something besides wx.CallLater(1000, self.Tick)?

Snippet :

import wx, re, time, win32api, calendar

class TimeDate :

    def __init__ (self) :

        self.Tick()

    def Tick (self) :

        self.Year     = int(time.strftime("%Y"))
        self.Month    = int(time.strftime("%m"))
        self.Calendar = calendar.month(self.Year, self.Month)
        self.Date     = time.strftime('%A, %B %d, %Y')
        self.Time     = time.strftime('%I:%M %S %p')

        print self.Time

        wx.CallLater(1000, self.Tick)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
294 views
Welcome To Ask or Share your Answers For Others

1 Answer

What you want is wx.Timer, not wx.CallAfter or wx.CallLater. See the following tutorial on timers for more information:

http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/

Both of the those "Call*" methods only fire once.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...