Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python wx.CallLater对我不起作用_Python_Wxpython - Fatal编程技术网

Python wx.CallLater对我不起作用

Python wx.CallLater对我不起作用,python,wxpython,Python,Wxpython,我想使用wx.CallLater:我有两个函数,它们将在循环中相互调用,但每次调用前有3秒的中断。问题是:当我的程序处于“goto01”状态时,它会在调用“Notify”之前正确地等待3秒钟。但当程序处于“Notify”状态时,会立即调用“goto01”。为什么在这一点上没有3秒的中断? 这是我的代码&在这两个函数的最后一行,我有一个wx.CallLater事件: self.speed = 3000 def Notify(self): self.zeit.Destroy() s

我想使用wx.CallLater:我有两个函数,它们将在循环中相互调用,但每次调用前有3秒的中断。问题是:当我的程序处于“goto01”状态时,它会在调用“Notify”之前正确地等待3秒钟。但当程序处于“Notify”状态时,会立即调用“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)
self.speed=3000
def通知(自我):
self.zeit.Destroy()
self.zeitint=self.zeitint+1
时间=整(自整/2)
self.zeit=wx.StaticText(self.friendlygamepanel,-1,“%d.Spielminute%”(time),(325+self.dx,9))
尝试:
self.ticker.Destroy()
self.picplayer1but.Destroy()
除:
通过
如果self.zeitint%2==1:
self.ticker=wx.TextCtrl(self,-1,teamname[0]+“ist im Ballbesitz.”,
大小=(340320),位置=(195+self.dx,160),样式=wx.TE_RICH2 | wx.TE_多行| wx.TE_NO_VSCROLL)
self.ticker.setbackgroundcolor((128191130))
self.ticker.SetStyle(0,len(teamname[0]),wx.TextAttr(“黑色”,wx.nullColor,self.font))
wx.CallLater(int(self.speed),self.goto01(players,self.playerpics))
其他:
self.ticker=wx.TextCtrl(self,-1,oppteamname[0]+“ist im Ballbesitz.”,
大小=(340320),位置=(195+self.dx,160),样式=wx.TE_RICH2 | wx.TE_多行| wx.TE_NO_VSCROLL)
自售股票代码挫折背景色((205173,65))
self.ticker.SetStyle(0,len(oppteamname[0]),wx.texttr(“黑色”,wx.nullcolor,self.font))
wx.CallLater(int(self.speed),self.goto01(opplayers,self.opplayerpics))
def goto01(自身、打印机、图片):
如果self.zeitint%2==1:
picpos=0
其他:
picpos=460
self.whichplayer=random.randint(0,2)
self.whichopplayer=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(播放器[self.whichplayer][0]),wx.texttr(“黑色”,wx.nullcolor,self.font))
self.picplayer1=wx.Image(图片[self.whichplayer],wx.BITMAP\u TYPE\u BMP).ConvertToBitmap()
self.picplayer1but=wx.BitmapButton(self.friendlygamepanel,-1,self.picplayer1,pos=(90+self.dx+picpos,180))
如果self.zeitint<60:
wx.CallLater(int(self.speed)、self.Notify)

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

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

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

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

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

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

wx.CallLater(numberOfMilliSecs, myFunction, arg1, arg2)

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

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

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

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

wx.CallLater(numberOfMilliSecs, myFunction, arg1, arg2)

这是毫秒,你写的
numberOfSecs
太正确了。很抱歉。固定的!这是毫秒,你写的
numberOfSecs
太正确了。很抱歉。固定的!