当我在后台下载视频时,我使用线程来保持我的UI的活动状态
下面是调用线程函数的按钮
button = Button(root, text="submit", background='#856ff8', foreground='black', font=BOLD,
command=lambda:thread("video url from the internet"))
这是线程函数
def thread(url):
update_label.configure(text='downloading..')
thread = threading.Thread(target=downloadVideo, args=(url))
thread.start()
这里是下载视频功能
def downloadVideo(url):
try:
urllib.request.urlretrieve(url, 'last video you downloaded.mp4')
update_label.configure(text="download successfully!")
except:
update_label.configure(text="download failed!")
我得到了这个错误
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
TypeError: downloadVideo() takes 1 positional argument but 133 were given
错误在这一行:
thread = threading.Thread(target=downloadVideo, args=(url))
您试图创建一个参数元组,但您只是在插入一个字符串
添加一个额外的“,”:
thread = threading.Thread(target=downloadVideo, args=(url,))
相关问题 更多 >
编程相关推荐