-
添加进度组件
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
相关推荐
空空潍6 小时前
Miniconda完整安装教程(win版)深兰科技6 小时前
深兰科技与淡水河谷合作推进:矿区示范加速落地weixin_586061466 小时前
JavaScript中Redux-Thunk处理异步Action的任务流2401_897190557 小时前
Golang怎么写TODO待办应用_Golang TODO应用教程【深入】m0_678485457 小时前
CSS实现浮动图标与文本居中对齐_配合浮动与flexYuanDaima20487 小时前
二分查找基础原理与题目说明2401_887724507 小时前
uni-app动画效果实现 uni-app如何使用animation APILuca_kill7 小时前
实战指南:用 Python + NLP 搭建一套轻量级 AI 舆情监控系统七颗糖很甜7 小时前
python实现全国雷达拼图数据的SCIT风暴识别m0_748839497 小时前
mysql如何处理不走索引的OR查询_使用UNION ALL优化重写