首页 > 解决方案 > 如何将生成的值放入组合框中?

问题描述

我正在使用 python 制作一个 You Tube Video Downloader。我对python非常陌生。我正在使用 tkinter 和 pytube 来制作这个应用程序。我首先从用户那里获取链接,然后我希望他们从三个选项中进行选择,然后再从生成的选项中进行选择。但是,不幸的是,我不知道为什么它们没有出现在我的组合框中。任何帮助,将不胜感激。

from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from pytube import YouTube

root = Tk()
root.title("YouTube Downloader")
root.geometry("350x360") # set window
root.columnconfigure(0,weight=1) # set all content in middle

Folder_Name = ""

generatedChoices = ""

global myChoices
myChoices = ["Video", "Video Without Audio", "Only Audio"]

global myChoicesb

# File Location Function
def openLocation():
    global Folder_Name
    Folder_Name = filedialog.askdirectory()
    if(len(Folder_Name) > 1):
        Errorlocation.config(text=Folder_Name,fg="green")

    else:
        Errorlocation.config(text="Please Choose Folder!",fg="red")

# Download Video
def downloadVideo():
    choice=ytdchoices.get()
    url = ytdEntry.get()

    if(len(url)>1):
        ytdError.config(text="")
        global yt
        yt = YouTube(url) 

# Download Function
    select.download(Folder_Name)
    ytdError.config(text="Download Completed!")

# Generate Quality Function
def generateQuality():
    choice = ytdchoices.get()
    url = ytdEntry.get()
    yt = YouTube(url)
    global generatedChoices
    generatedChoices = yt.streams
    ytdError.config(text="Qualities Generated !!!",fg="green")

    if(choice == myChoices[0]):
            select = yt.streams.filter(progressive=True)

    elif(choice == myChoices[1]):
            select = yt.streams.filter(adaptive=True)

    elif(choice == myChoices[2]):
            select = yt.streams.filter(only_audio=True)

    else:
            ytdError.config(text="Choose Your Quality!",fg="red")

# YouTube Downloader Link Label
ytdLabel = Label(root,text="Enter the URL here.",font=("jost",15))
ytdLabel.grid()

# Entry Box
ytdEntryVar = StringVar()
ytdEntry = Entry(root,width=50,textvariable=ytdEntryVar)
ytdEntry.grid()

# Error Message
ytdError = Label(root, text="",fg="red",font=("jost",10))
ytdError.grid()

# Asking Save File Label
saveLabel = Label(root,text="Save The Video File",font=("jost",13,"bold"))
saveLabel.grid()

# Button of Save File
saveEntry = Button(root,width=10,bg="red",fg="white",text="Choose Path",font=("jost",10,"bold"),command=openLocation)
saveEntry.grid()

# Error Message of Location
Errorlocation = Label(root,text="",fg="red",font=("jost",10))
Errorlocation.grid()

# Download Quality 
ytdQuality = Label(root,text="Select Quality",font=("jost",15))
ytdQuality.grid()

# Spacing
spaceLabela = Label(root,text="")
spaceLabela.grid()

# Combo Box
ytdchoices = ttk.Combobox(root,values=myChoices)
ytdchoices.grid()

# Spacing
spaceLabelb = Label(root,text="")
spaceLabelb.grid()

# Generate Quality
generate = Button(root,width=13,bg="red",fg="white",text="Generate Quality",font=("jost",10,"bold"),command=generateQuality)
generate.grid()

# Spacing
spaceLabelc = Label(root,text="")
spaceLabelc.grid()

# Combo Box
ytdchoicesb = ttk.Combobox(root,values=generatedChoices)
ytdchoicesb.grid()

# Spacing
spaceLabeld = Label(root,text="")
spaceLabeld.grid()

# Download Button
downloadbutton = Button(root,text="Download",font=("jost",10,"bold"),width=10,bg="red",fg="white",command=downloadVideo)
downloadbutton.grid()

root.mainloop()

标签: pythontkinter

解决方案


推荐阅读