keyword -youtube converter mp4 ,youtube converter mp4 converter
It has to work,but it gives me this error:
<code>File "C:\Users\ХарисВМладенов\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\customtkinter\windows\widgets\ctk_button.py", line 553, in _clicked self._command() TypeError: Download() missing 1 required positional argument: 'url_var'</code>
Here is my code:
import tkinter as tk
import customtkinter as ctk
from pytube import YouTube
def Download(url_var):
try:
ytlink = link.get(url_var)
ytObject = YouTube(ytlink)
video = ytObject.streams.get_highest_resolution(url_var)
video.download(video)
except:
print("Invalid link")
print("Download Compleate")
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("blue")
app = ctk.CTk()
app.geometry("720x480")
app.title("YouTube Download")
url_var = tk.StringVar()
title = ctk.CTkLabel(app, text="Insert a YouTube link")
title.pack(padx=10, pady=10)
link = ctk.CTkEntry(app, width=350, height=40, textvariable=url_var)
link.pack()
download = ctk.CTkButton(app, text="Download", command=Download)
download.pack()
app.mainloop()
I tried without the url_var but then it prints “Invalid link”
It seems like the issue in your code is related to the url_var
parameter not being passed correctly to the Download
function when the Download
button is clicked. The Download
function expects the url_var
parameter to be passed, but the way you have set up the command
for the download
button is causing this error.
To fix this, you can use a lambda function to pass the url_var
to the Download
function when the button is clicked. Here’s how you can modify your code:
import tkinter as tk
import customtkinter as ctk
from pytube import YouTubedef Download():
try:
ytlink = link.get()
ytObject = YouTube(ytlink)
video = ytObject.streams.get_highest_resolution()
video.download()
print(“Download Complete”)
except:
print(“Invalid link”)ctk.set_appearance_mode(“System”)
ctk.set_default_color_theme(“blue”)app = ctk.CTk()
app.geometry(“720×480”)
app.title(“YouTube Download”)title = ctk.CTkLabel(app, text=”Insert a YouTube link”)
title.pack(padx=10, pady=10)url_var = tk.StringVar()
link = ctk.CTkEntry(app, width=350, height=40, textvariable=url_var)
link.pack()download = ctk.CTkButton(app, text=”Download”, command=lambda: Download())
download.pack()app.mainloop()
With this modification, the url_var
is obtained directly from the link
entry widget inside the Download
function. The lambda function is used to pass the correct value of url_var
to the Download
function when the button is clicked, resolving the “TypeError: Download() missing 1 required positional argument: ‘url_var'” error.