Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 tkinter中使用“后”方法的延时独立工作_Python_Tkinter - Fatal编程技术网

Python tkinter中使用“后”方法的延时独立工作

Python tkinter中使用“后”方法的延时独立工作,python,tkinter,Python,Tkinter,以这个例子为例 在这里,按下“下一步”按钮时,您会注意到标签“0”会增加到9,但10会很快添加到历史区域中,尽管它应该发生在倒计时功能结束后。 我应该如何确保串行执行? 谢谢。after方法立即返回。它不会等待超时过期。当数字列表为空时,应将history_text.set调用放在倒计时函数中 顺便说一句,你可以用if-list-of-numbers代替if-lenlist-of-of-numbers==0来检查列表是否为空。我不明白。您的预期输出是什么?请打印LenRange1100,看看您得

以这个例子为例

在这里,按下“下一步”按钮时,您会注意到标签“0”会增加到9,但10会很快添加到历史区域中,尽管它应该发生在倒计时功能结束后。 我应该如何确保串行执行? 谢谢。

after方法立即返回。它不会等待超时过期。当数字列表为空时,应将history_text.set调用放在倒计时函数中


顺便说一句,你可以用if-list-of-numbers代替if-lenlist-of-of-numbers==0来检查列表是否为空。

我不明白。您的预期输出是什么?请打印LenRange1100,看看您得到了什么。对于制造商和stovfl,我在我的原始帖子中更新了代码。请运行它,然后您会注意到,10会在倒计时结束之前很快被追加到文本区域。我已经尝试提供最低限度的可验证示例来解释我的问题。请运行我的代码,然后您就可以理解我的观点并删除对问题的反对票。看来您是对的。”“后”是非阻塞的。此外,您建议检查列表是否存在也很有帮助。我已经在我的原始帖子中更新了代码,以便向其他人澄清我的问题。当我将“history_text_list.append10”和“history_text.setstrhistory_text_list”移动到倒计时函数中的else子句时,就实现了所需的功能。谢谢
from tkinter import *
history_text_list=[]
window=Tk()
window.geometry("1366x768+1+1")
winner_lbl=Label(window, text="0", fg='red', font=("Comic Sans MS", 96))
winner_lbl.place(x=5, y=5)
a_pixel = PhotoImage(width=1, height=1)
next_btn=Button(window, text="Next", font=("Comic Sans MS", 32), fg='blue', image=a_pixel, height = 70 , width = 130,compound="c")
next_btn.place(x=235, y=70)
history_text = StringVar()
history_label = Label(window, textvariable=history_text, wraplength=850, font=("Comic Sans MS", 16),justify="left",anchor="nw")
history_label.place(x=410, y=5)
def countdown(list_of_numbers):
    print('in function list-'+str(list_of_numbers))
    winner_lbl['fg'] = 'black'
    winner_lbl['text'] = list_of_numbers[0]
    list_of_numbers.pop(0)
    if list_of_numbers:
        window.after(500,countdown,list_of_numbers)
    else:
        winner_lbl['fg'] = 'red'
        return
def MyButtonClicked(self):
    one_to_hundred=list(range(1,10))
    countdown(one_to_hundred)
    history_text_list.append(10)
    history_text.set(str(history_text_list))
next_btn.bind('<Button-1>', MyButtonClicked)
window.mainloop()