函数接受1个位置参数,但给出了133个位置参数

2024-06-26 17:52:08 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在后台下载视频时,我使用线程来保持我的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

Tags: 函数textinselfurl视频configuredef
1条回答
网友
1楼 · 发布于 2024-06-26 17:52:08

错误在这一行:

thread = threading.Thread(target=downloadVideo, args=(url))

您试图创建一个参数元组,但您只是在插入一个字符串

添加一个额外的“,”:

thread = threading.Thread(target=downloadVideo, args=(url,))

相关问题 更多 >