我调用了函数playVideo()
,然后使用tkinterroot.after(5, playVideo)
循环视频帧。在我调用playVideo之后,我有更多的代码来处理在playVideo中填充的列表。问题是此代码在playVideo循环结束之前执行。
有没有一种方法可以强制程序等待playVideo((完成后再继续?
def myFunc():
global myList
# call to the looping function
playVideo()
# some code that handles the list
def playVideo():
global myList
ret, frame = currCapture.read()
if not ret:
currCapture.release()
print("Video End")
else:
# some code that populates the list
root.after(5, playVideo)
您可以尝试使用wait_variable()
函数:
# create a tkinter variable
playing = BooleanVar()
然后使用wait_variable()
等待playVideo()
:完成
def myFunc():
global myList
# call to the looping function
playVideo()
# some code that handles the list
print('Handling list ...')
# wait for completion of playVideo()
root.wait_variable(playing)
# then proceed
print('Proceed ...')
def playVideo()
global myList
ret, frame = currCapture.read()
if not ret:
currCapture.release()
print("Video End")
playing.set(False) # update variable to make wait_variable() return
else:
# some code that populates the list
root.after(5, playVideo)