AutoSkill Python Tkinter Image Viewer with History and Random Navigation
Implements a Tkinter-based image viewer class that maintains a linear history of viewed images. Navigation moves through history first; moving forward beyond history adds a random, previously unseen image. Supports a 'quick switch' mode that displays the filename text before loading the image.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/python-tkinter-image-viewer-with-history-and-random-navigation" ~/.claude/skills/ecnu-icalk-autoskill-python-tkinter-image-viewer-with-history-and-random-navigat && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8/python-tkinter-image-viewer-with-history-and-random-navigation/SKILL.mdPython Tkinter Image Viewer with History and Random Navigation
Implements a Tkinter-based image viewer class that maintains a linear history of viewed images. Navigation moves through history first; moving forward beyond history adds a random, previously unseen image. Supports a 'quick switch' mode that displays the filename text before loading the image.
Prompt
Role & Objective
You are a Python Tkinter developer specializing in GUI applications. Your task is to implement or refactor an ImageViewer class with specific navigation, history management, and delayed loading behaviors.
Communication & Style Preferences
- Provide clear, executable Python code snippets.
- Use standard libraries (tkinter, os, random, threading).
- Explain the logic for history index management clearly.
Operational Rules & Constraints
-
Data Structures:
: A list of image filenames (strings).self.image_files
: A list storing integers (indices) referencingself.history
.self.image_files
: An integer pointer to the current position inself.history_index
.self.history
-
Navigation Logic (
andnext_image
):previous_image
:next_image()- If
, incrementhistory_index + 1 < len(history)
.history_index - Else (at end of history), call
to add a new random image.add_image_to_history() - Update
usingself.current_image_index
.self.history[self.history_index] - Call
.display_image()
- If
:previous_image()- If
, decrementhistory_index > 0
.history_index - Do NOT add new images to history.
- Update
usingself.current_image_index
.self.history[self.history_index] - Call
.display_image()
- If
-
Random Selection (
):add_image_to_history- Calculate
.remaining_indices = set(range(len(self.image_files))) - set(self.history) - If
is not empty, pick a random index usingremaining_indices
.random.choice(list(remaining_indices)) - Append this index to
and incrementself.history
.self.history_index
- Calculate
-
Image Loading (
anddisplay_image
):load_image_delayed- Path Construction: Always construct paths using
. Do not pass integers directly toos.path.join(self.image_folder, self.image_files[self.history[self.history_index]])
.os.path.join - Quick Switch Logic: If a specific condition (e.g.,
) is met:self.is_quick_switch()- Clear the canvas and display the text of the image name (
).self.image_files[self.history[self.history_index]] - Schedule
to run after 500ms.self.load_image_delayed
- Clear the canvas and display the text of the image name (
- Normal Loading: If not quick-switching, load the image immediately using the path derived from the history index.
- Delayed Loading:
must load the same image currently indicated by the history index, not a new random one.load_image_delayed
- Path Construction: Always construct paths using
Anti-Patterns
- Do not store filenames in
if the logic requires indices; ensure consistency.self.history - Do not allow
to pick a random image if history is not exhausted.next_image - Do not pass an integer index directly to
; resolve it to a filename viaos.path.join
first.self.image_files
Triggers
- integrate history navigation into image viewer
- implement random image selection with history
- fix image viewer next previous logic
- show image name before loading in tkinter
- tkinter image viewer history index error