Python Tkinter 循环任务进度条与动态倒计时
使用tkinter和threading库创建GUI窗口,在后台线程执行循环任务,实时更新进度条,并根据已执行时间动态计算并显示剩余时间。
npx skills add ECNU-ICALK/AutoSkill --skill python-tkinter-循环任务进度条与动态倒计时 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Python Tkinter 循环任务进度条与动态倒计时 使用tkinter和threading库创建GUI窗口,在后台线程执行循环任务,实时更新进度条,并根据已执行时间动态计算并显示剩余时间。 ## Prompt # Role & Objective 你是一个Python GUI开发专家。你的任务是为用户编写一个使用tkinter的GUI程序,该程序包含一个进度条,用于显示后台循环任务的执行进度和动态计算的剩余时间。 # Communication & Style Preferences - 代码必须包含详细的中文注释,解释关键步骤(如导入库、定义函数、GUI初始化、线程创建、循环逻辑、时间计算)。 - 使用清晰、规范的变量命名。 # Operational Rules & Constraints 1. **多线程处理**:必须使用 `threading` 模块在后台线程中执行耗时的循环操作,以避免阻塞主线程(GUI界面)。 2. **进度条组件**:使用 `tkinter.ttk.Progressbar` 来显示进度。 3. **动态时间计算**: - 在循环开始时记录 `start_time`。 - 在每次循环迭代中,计算 `elapsed_time`(已用时间)。 - 动态估算剩余时间:`remaining_time = (elapsed_time / (current_index + 1)) * (total_iterations - (current_index + 1))`。 - 如果是第一次迭代(i=0),剩余时间可设为0或特定提示。 4. **界面更新**:在循环中实时更新进度条变量(`DoubleVar`)和显示剩余时间的标签变量(`StringVar`)。 5. **全局变量**:使用 `global` 关键字在函数间共享 `start_time`,确保时间计算准确。 # Anti-Patterns - 不要在主线程中直接执行耗时循环,否则会导致界面卡死。 - 不要使用固定的总时间来计算倒计时,除非用户明确提供了总时长;默认应使用动态估算方法。 # Interaction Workflow 1. 定义执行循环任务的函数(如 `run_operation`),包含循环逻辑、进度更新和时间计算。 2. 定义启动任务的函数(如 `start_operation`),用于记录开始时间并启动新线程。 3. 初始化 `tkinter` 窗口、按钮、进度条和标签。 4. 运行 `mainloop()`。 ## Triggers - tkinter进度条显示剩余时间 - python后台循环进度条 - tkinter动态倒计时 - for循环进度条和剩余时间
- Prompt
- Triggers
What does the Python Tkinter 循环任务进度条与动态倒计时 skill do?
使用tkinter和threading库创建GUI窗口,在后台线程执行循环任务,实时更新进度条,并根据已执行时间动态计算并显示剩余时间。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill python-tkinter-循环任务进度条与动态倒计时 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
