Python tkinter应用程序在0错误时运行时不响应?

2024-10-02 14:24:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我正在尝试开发一个基本应用程序,使用PytubeAPI通过url下载YouTube视频。不幸的是,我的IDE(pycharm)没有显示任何错误,我的程序崩溃并显示“无响应”消息。有人有什么想法吗?感谢所有的帮助

干杯:)

我尝试过删除Pytube函数 我也试着重新启动Pycharm和项目 我尝试过删除函数和代码的不同配置

程序应该在小部件处于正确的x+y位置时运行,然后再运行任何小部件功能

    import os
    import tkinter as tk
    from pytube import YouTube

     root = tk.Tk()
    root.title("YouTube converter")
    root.geometry('800x300')

root.iconbitmap(r'C:\\Users\\matthew.harris\\youtube_tool\\youtube_tool\\icon.ico')
    root.resizable(0, 0)
    root.tk_setPalette(background='light grey')

    save_location = 'C:\\Users\\', os.environ.get('USER'), '\\Desktop'
    link = input()
    yt = YouTube(link)

    mp4files = yt.filter('mp4')
    download_func = yt.get(mp4files[-1].extension, mp4files[-1].resolution)


def get_video():
    try:
        download_func.download(save_location)
    except download_func as error:
        print('Some error')
        print('task completed')


textEntry = tk.Entry(root, font=100, width=50, bg='white', command=get_video())
textEntry.pack(side=tk.TOP, padx=0, pady=40)

youtubeID = tk.Label(root, text='Youtube video url')
youtubeID.place(x=1, y=45)

Convert_Button = tk.Button(root, text='Convert', command=get_video()).place(x=700, y=40)

videoOption = tk.IntVar()
R1 = tk.Radiobutton(root, text='MP3', variable=videoOption, value='MP3').place(x=500, y=100)
R2 = tk.Radiobutton(root, text='Video', variable=videoOption, value='Video').place(x=200, y=100)

root.mainloop()
``

Tags: textimport程序urlgetyoutubedownloadvideo