Using wx.CallLater in wxPython

本秂侑毒 提交于 2020-01-16 16:16:04

问题


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)

回答1:


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.




回答2:


Use wx.CallAfter instead - wx.CallLater is a class and should be used differently.

wx.CallAfter, on the other hand, seems to be exactly what you need.




回答3:


I think both wx.CallAfter and wx.CallLater are called only once.....



来源:https://stackoverflow.com/questions/5851824/using-wx-calllater-in-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!