-
添加进度组件
pythondef 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) // 2 y = (screen_height - window_height) // 2 progress_window.geometry(f"{window_width}x{window_height}+{x}+{y}") -
创建进度更新方法
pythondef update_progress(progress): progress_bar['value'] = progress progress_window.update_idletasks() -
调用下载方法,传入进度更新方法
pythonls_setoption.get_dump_video(video_dir, progress_callback=update_progress) progress_window.destroy() -
使用子线程调用下载方法,注意用子线程,否则下载过程UI会卡死,进度不更新
pythondownload_thread = threading.Thread(target=download) download_thread.start()
python使用tkinter添加下载进度UI
ChatGPT攻城狮2024-07-10 7:03
相关推荐
一晌小贪欢12 分钟前
【Python数据分析】数据分析与可视化dreams_dream3 小时前
Flaskmywpython3 小时前
用Python和Websockets库构建一个高性能、低延迟的实时消息推送服务ZPC82103 小时前
FPGA 部署ONNX一晌小贪欢4 小时前
Python键盘鼠标自动化库详解:从入门到精通穿西装的水獭4 小时前
python将Excel数据写进图片中xiaoxiongip6664 小时前
假设两个设备在不同网段,网关怎么设置才能通呢逻极4 小时前
Scikit-learn 实战:15 分钟构建生产级中国房价预测模型行板Andante4 小时前
AttributeError: ‘super‘ object has no attribute ‘sklearn_tags‘解决tryCbest4 小时前
Python基础之爬虫技术(一)