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