在wxPython中使用wx.CallLater [英] Using wx.CallLater in wxPython

查看:397
本文介绍了在wxPython中使用wx.CallLater的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个处理基本时间相关功能的对象。我想要这样,当引用任何属性(例如 self.Time )时,它们都是最新的。但是,由于某些原因, wx.CallLater(1000,self.Tick)似乎没有更新属性。它只会打印一次 self.Time ,而不是每秒打印一次(就像我想要的那样)。

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).

我将如何获得自己想要的行为?除了 wx.CallLater(1000,self.Tick)之外,我还应该使用其他东西吗?

How would I go about getting the behavior I desire? Should I use something besides 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)


推荐答案

您想要的是wx.Timer,而不是wx.CallAfter或wx.CallLater。有关更多信息,请参见以下有关计时器的教程:

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/

这两个 Call *方法仅触发一次。

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

这篇关于在wxPython中使用wx.CallLater的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆