wx.CallLater对我不起作用

时间:2012-10-23 08:52:11

标签: python wxpython

我想使用wx.CallLater:我有两个函数,它们应该在一个循环中相互调用,但在每次调用之前休息3秒。问题是:当我的程序在“goto01”中时,它会在“Notify”被调用之前正确等待3秒。但是当程序处于“通知”时,则立即调用“goto01”。为什么此时没有3秒钟的突破? 这是我的代码&在这两个函数的最后一行中,我有一个wx.CallLater事件:

self.speed = 3000

def Notify(self):
    self.zeit.Destroy()
    self.zeitint = self.zeitint + 1
    time = round(self.zeitint/2)
    self.zeit = wx.StaticText(self.friendlygamepanel, -1, '%d. Spielminute'%(time), (325+self.dx,9))
    try:
        self.ticker.Destroy()
        self.picplayer1but.Destroy()

    except:
        pass
    if self.zeitint % 2 == 1:
        self.ticker = wx.TextCtrl(self, -1, teamname[0]+' ist im Ballbesitz.',
                    size=(340, 320), pos=(195+self.dx,160), style=wx.TE_RICH2|wx.TE_MULTILINE|wx.TE_NO_VSCROLL)
        self.ticker.SetBackgroundColour((128,191,130))
        self.ticker.SetStyle(0, len(teamname[0]), wx.TextAttr("BLACK", wx.NullColour, self.font))
        wx.CallLater(int(self.speed),self.goto01(players,self.playerpics))

    else:
        self.ticker = wx.TextCtrl(self, -1, oppteamname[0]+' ist im Ballbesitz.',
                    size=(340, 320), pos=(195+self.dx,160), style=wx.TE_RICH2|wx.TE_MULTILINE|wx.TE_NO_VSCROLL)
        self.ticker.SetBackgroundColour((205,173,65))
        self.ticker.SetStyle(0, len(oppteamname[0]), wx.TextAttr("BLACK", wx.NullColour, self.font))
        wx.CallLater(int(self.speed),self.goto01(oppplayers,self.oppplayerpics))


def goto01(self,theplayer,thepicture):
    if self.zeitint % 2 == 1:
        picpos = 0
    else:
        picpos = 460
    self.whichplayer = random.randint(0,2)
    self.whichoppplayer = random.randint(0,2)
    last = self.ticker.GetLastPosition()
    self.ticker.AppendText('\n\n'+theplayer[self.whichplayer][0]+' hat den Ball.')
    self.ticker.SetStyle(last, last+2+len(theplayer[self.whichplayer][0]), wx.TextAttr("BLACK", wx.NullColour, self.font))
    self.picplayer1 = wx.Image(thepicture[self.whichplayer], wx.BITMAP_TYPE_BMP).ConvertToBitmap()
    self.picplayer1but = wx.BitmapButton(self.friendlygamepanel,-1,self.picplayer1,pos=(90+self.dx+picpos,180))
    if self.zeitint < 60:
        wx.CallLater(int(self.speed),self.Notify)

2 个答案:

答案 0 :(得分:3)

当你用变量调用函数时,你告诉wxPython立即调用它。这就像你通常调用一个函数一样。您可以将参数传递给它:

http://wxpython-users.1045709.n5.nabble.com/wx-CallLater-issue-td4885884.html

正如该链接指出的那样,CallLater的签名是:

(自我,毫米,可赎回,* args,** kwargs)

这意味着您应该可以执行类似

的操作
wx.CallLater(numberOfMilliSecs, myFunction, arg1, arg2)

答案 1 :(得分:0)

我知道,当我只是调用“goto01”而不是“goto01(variable1,variable2)”时,它就可以了。我能够更改我的代码,以便在调用“goto”时不必使用这些变量,但我仍然不知道为什么wx.CallLater不能使用变量?!