0
import pytube
from tkinter import *
import threading

def download1():
    link = test_url.get()

    yt = pytube.YouTube(link)
    videos = yt.get_videos()

    n = quality.get()
    vid = videos[n - 1]

When i try to thread the download i get an error stating that IndexError: list index out of range originating at vid = videos[n - 1]

    destination = destination_test.get()
    vid.download(destination)

This issue happens when i try to thread the download here.

def thread():
    download2 = threading.Thread(target=download1() )
    download2.start()
    download1()


root = Tk()
test_url = StringVar()
quality = IntVar()
destination_test = StringVar()


url_label = Label(text='Enter Url')
quality_label = Label(text='quality')
destination_label = Label(text='Destination')
url_label.grid(row=0, column=0)
quality_label.grid(row=1, column=0)
destination_label.grid(row=2, column=0)
url_entry = Entry(textvariable=test_url)
url_entry.grid(row=0, column=1)
quality_entry = Entry(textvariable=quality)
quality_entry.grid(row=1, column=1)
destination_entry = Entry(textvariable=destination_test)
destination_entry.grid(row=2, column=1)
download = Button(text='download', command=thread())
download.grid(row=3, column=1)

root.mainloop()
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Hi there, welcome to Stackoverflow! I recommend you take the [welcome tour](https://stackoverflow.com/tour) to know your way arround here (and earn your first badge also ;) ). Also to improve the chances of getting useful answers please check [how to ask](https://stackoverflow.com/help/asking) and also how to create [Complete, Minimal, and Verifiable examples](https://stackoverflow.com/help/mcve). – DarkCygnus Jul 24 '17 at 00:27
  • `target` and `command` expects references to functions not return values. If you print the value of link, you'll most likely see that it is empty. – Lafexlos Jul 24 '17 at 05:59
  • 1
    Possible duplicate of [Why is Button parameter "command" executed when declared?](https://stackoverflow.com/questions/8269096/why-is-button-parameter-command-executed-when-declared) – Lafexlos Jul 24 '17 at 05:59
  • @Lafexlos thanks for the solution I had been stuck on that one for a while. I would also like to ask if you know any frameworks I could use to create a material design GUI. – Matthew Perry Jul 24 '17 at 20:42
  • 1
    Possible duplicate of [Why is Button parameter “command” executed when declared?](https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared) – J.J. Hakala Jan 08 '18 at 10:38
  • This is a duplicate of https://stackoverflow.com/questions/5767228/ and also https://stackoverflow.com/questions/11792629/ (the same problem in two different contexts; this code manages to show *both*). – Karl Knechtel Sep 05 '22 at 07:35

0 Answers0