3

I used thread to keep my UI alive while i download a video in the background

Here is the button that call the thread function

 button = Button(root, text="submit", background='#856ff8', foreground='black', font=BOLD, 
 command=lambda:thread("video url from the internet"))

here is the thread function

def thread(url):
update_label.configure(text='downloading..')
thread = threading.Thread(target=downloadVideo, args=(url))
thread.start()

Here is the downloadVideo function


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!")  

and i get this error

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
Yechiel babani
  • 344
  • 3
  • 13
  • If `args` is supposed to be a sequence of args and you're giving it a single value, then I think you need `args=(url,)` – khelwood Oct 21 '21 at 07:40

1 Answers1

4

error is in this line:

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

You're trying to create a tuple of args, but you're just parenthesizing a string

Add an extra ',':

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

4d61726b
  • 427
  • 5
  • 26