So I wrote a small youtube audio downloader app, but I dont know how to pass the value that user inserts to the function.
I tested the app without the GUI, it works. So when I created GUI using custom tkinter(this is my first time using it) I get the following error: TypeError: Download() missing 1 required positional argument: 'link' Here is the code
import customtkinter
from pytube import YouTube
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
root = customtkinter.CTk()
root.geometry("500x350")
def Download(link):
youtubeObject = YouTube(link)
youtubeObject = youtubeObject.streams.get_audio_only()
try:
youtubeObject.download()
except:
print("Error!")
print("Success!")
frame = customtkinter.CTkFrame(master=root)
frame.pack(pady = 20, padx = 60, fill="both", expand = True)
entry = customtkinter.CTkEntry(master=frame, placeholder_text= "URL")
entry.pack(pady=12, padx = 10)
button = customtkinter.CTkButton(master=frame, text="Download", command=Download)
button.pack(pady=12, padx = 10)
root.mainloop()
CodePudding user response:
You should modify Download
to get the value from the entry widget once it's called, rather than passing it in.
def Download():
link = entry.get()
...