Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

python - Using wx.CallLater in wxPython

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...