0

我想使用 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)
4

2 回答 2

3

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

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

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

(self, millis, callable, *args, **kwargs)

这意味着你应该能够做类似的事情

wx.CallLater(numberOfMilliSecs, myFunction, arg1, arg2)
于 2012-10-23T13:23:32.250 回答
0

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

于 2012-10-23T09:10:21.597 回答