在 wxPython 中使用 wx.CallLater
我正在尝试创建一个处理基本时间相关功能的对象。我想要它,这样当引用任何属性(例如 self.Time )时,它们都是最新的。但是,由于某种原因 wx.CallLater(1000, self.Tick) 似乎没有更新属性。它只会打印 self.Time 一次,而不是每秒打印一次(就像我想要的那样)。
我将如何获得我想要的行为?我应该使用 wx.CallLater(1000, self.Tick) 之外的东西吗?
片段:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你想要的是wx.Timer,而不是wx.CallAfter或wx.CallLater。有关详细信息,请参阅以下有关计时器的教程:
http: //www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/
这两个“Call*”方法仅触发一次。
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.
使用
wx.CallAfter
代替 -wx.CallLater
是一个类,应该以不同的方式使用。另一方面,wx.CallAfter 似乎正是您所需要的。
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.我认为
wx.CallAfter
和wx.CallLater
都只被调用一次......I think both
wx.CallAfter
andwx.CallLater
are called only once.....