- 添加进度组件
def download(): # 创建下载进度框progress_window = tk.Toplevel()progress_window.title("下载进度")progress_label = tk.Label(progress_window, text="正在下载视频文件...")progress_label.pack(pady=10)progress_bar = ttk.Progressbar(progress_window, orient="horizontal", length=300, mode="determinate")progress_bar.pack(pady=10)# 获取窗口宽高并居中显示progress_window.update_idletasks()window_width = progress_window.winfo_width()window_height = progress_window.winfo_height()screen_width = progress_window.winfo_screenwidth()screen_height = progress_window.winfo_screenheight()x = (screen_width - window_width) // 2y = (screen_height - window_height) // 2progress_window.geometry(f"{window_width}x{window_height}+{x}+{y}")
-
创建进度更新方法
def update_progress(progress):progress_bar['value'] = progressprogress_window.update_idletasks()
-
调用下载方法,传入进度更新方法
ls_setoption.get_dump_video(video_dir, progress_callback=update_progress)progress_window.destroy()
-
使用子线程调用下载方法,注意用子线程,否则下载过程UI会卡死,进度不更新
download_thread = threading.Thread(target=download)download_thread.start()