首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用asksaveas函数

无法使用asksaveas函数
EN

Stack Overflow用户
提问于 2020-08-13 18:22:28
回答 1查看 140关注 0票数 0

我正在制作一个GUI应用程序,用户可以从youtube下载任何视频,下面是我使用的代码:

代码语言:javascript
复制
from pytube import YouTube
from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import *
from threading import *

root=Tk()

root.iconbitmap('yticon.ico')
root.title('Youtube Video Downloader')
root.resizable(0,0)

file_size=0
url=''

def downThread():
    p1=Thread(target=downloader)
    p1.start()
def progress(chunk,file_handle,remaining):
    global download_status
    file_download=file_size-remaining
    per=(file_download/file_size)*100
    download_status.config(text='{:00.0f}% downloaded'.format(per))

def downloader():
    global file_size, download_status, url
    download_btn.config(state=DISABLED)
    download_status.place(x=200, y=250)
    #try:
    link=url.get()
    path=asksaveasfilename(title='Save File', defaultextension='.mp4', filetype=(('*.mp4', 'MP4 Files')))
    yt=YouTube(link, on_progress_callback=progress)
    video=yt.streams.filter(progressive=True, file_extension='mp4').first()
    file_size=video.filesize
    #assert isinstance(video, bytes)
    video.download(path)
    download_status.config(text='Download Finished...')
    res=messagebox.askyesno('Youtube Downloader','Do You want to download another video?')
    if res==1:
        url.delete(0,END)
        download_btn.config(state=NORMAL)
        download_status.config(text=' ')
    else:
        root.destroy()
    #except Exception as e:
     #   download_status.config(text='Failed!!There was an error')

imgfile=PhotoImage(file='yticon1.png')
back_img=Label(root, image=imgfile)
back_img.place(x=0,y=0,relwidth=1,relheight=1)
entr_url=Label(root, text='Enter Url', font='Algerian 15 bold')
entr_url.place(x=20,y=40)
url=Entry(root, width=30, bd=2, relief=SUNKEN, font=('Calibiri(Body)', 12))
url.place(x=140, y=40)
btnimg=PhotoImage(file='yt.png')
download_btn=Button(root, width=99, height=50, relief=RIDGE, activebackground='red', image=btnimg, command=downThread, bd=7)
download_btn.place(x=220, y=170)
download_status=Label(root, text='Please Wait...', font=('Arial',15))
root.geometry('700x400+150+150')
root.mainloop()

但是当我运行这段代码时,它给出了这个错误,我该如何解决它呢?

代码语言:javascript
复制
_tkinter.TclError: bad file type ".mp4", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"
EN

回答 1

Stack Overflow用户

发布于 2020-08-13 19:00:11

link=url.get()

path=asksaveasfilename(title='Save File', defaultextension='.mp4',filetype=(('*.mp4', 'MP4 Files')))

yt=YouTube(link,on_progress_callback=progress) ('*.mp4','mp4文件‘))`您必须这样做,因为文件类型将是列表形式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63393049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档