我正在尝试在pythontkinter中启动和停止progressbar以进行下载过程。我试图为下载进度设置一个线程并启动进程栏。然而,酒吧一直在营业,我得到了一个“如果你自己”的答案,你是不是停了_已启动。是否已设置():RecursionError:超过最大递归深度“错误。你知道吗
代码如下:
import time
import threading
import tkinter
from tkinter import ttk
from six.moves import urllib
def start_thread():
b_start['state'] = 'disable'
progbar.start()
thread = threading.Thread(target=tasks)
thread.start()
root.after(50, check_thread(thread))
def check_thread(thread):
if thread.is_alive():
root.after(50, check_thread(thread))
else:
progbar.stop()
b_start['state'] = 'normal'
def download_func():
urllib.request.urlretrieve('ftp://ftp.ebi.ac.uk/pub/databases/uniprot/knowledgebase/uniprot_sprot_varsplic.fasta.gz', 'uni.dat')
def tasks():
download_func()
root = tkinter.Tk()
progbar = ttk.Progressbar(root)
progbar.config(maximum=8,mode='indeterminate')
progbar.pack()
b_start = ttk.Button(root, text='Start',command=start_thread)
b_start.pack()
root.mainloop()
我做错什么了?!你知道吗
干杯, 卷曲的
问题出在函数上
事实上
立即重新执行
check_thread
,导致RecursionError
。after
的正确语法是root.after(<delay>, <function to execute>)
,因此,这里用解决问题。你知道吗
相关问题 更多 >
编程相关推荐