-1
from tkinter import *
import pytube
import threading

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

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

    n = quality.get()

    vid = videos[n - 1]

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

def test():
    threading.Thread(target=download()).start()

root = Tk()
test_url = StringVar()
quality = IntVar()
destination_test = StringVar()
url_label = Label(text='Enter Url')
quality_label = Label(text='quality')
url_label.grid(row=0, column=0)
quality_label.grid(row=1, column=0)
destination_label = Label(text='Destination')
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 = Button(text='download', command=test())
download_button.grid(row=3, column=1)
root.mainloop()

回溯(最后一次调用):文件“C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.4\helpers\pycharm_jb_unittest_runner.py”,第 35 行,在 main(argv=args, module=None, testRunner=unittestpy. TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING) 文件“C:\Python36\lib\unittest\main.py”,第 93 行,在init self.parseArgs(argv) 文件“C:\Python36\lib\unittest\main.py”,第 140 行,在 parseArgs self.createTests() 文件“C:\Python36\lib\unittest\main.py”,第 147 行,在 createTests self.module) 文件“C:\Python36\lib\unittest\loader.py”,第 219 行,在 loadTestsFromNames 套件 = [self.loadTestsFromName(name, module) for name in names] 文件“C:\Python36 \lib\unittest\loader.py",第 219 行,在套件中 = [self.loadTestsFromName(name, module) for name in names] 文件 "C:\Python36\lib\unittest\loader.py",第 153 行,在loadTestsFromName 模块 =导入(module_name) 文件“C:\Users\Matthew\PycharmProjects\test\test.py”,第 37 行,在 download_button = Button(text='download', command=test()) 文件“C:\Users\Matthew\ PycharmProjects\test\test.py”,第 19 行,在测试 threading.Thread(target=download()).start() 文件“C:\Users\Matthew\PycharmProjects\test\test.py”,第 13 行,在下载 vid = 视频 [n - 1] IndexError:列表索引超出范围

4

1 回答 1

2

因为您的变量“n”的值要么等于 0,要么比您的视频数量大 2 或更多。

无论 quality.get() 做什么,无论质量变量是什么n=quality.get(),最终都会导致错误...

于 2017-07-17T20:05:52.237 回答