# Tkinter Dialog State Persistence

> Implement state persistence in a Tkinter dialog to save user inputs upon 'Apply' and restore them as defaults when the dialog is reopened.

- Skill: `ecnu-icalk/tkinter-dialog-state-persistence` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/tkinter-dialog-state-persistence`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/tkinter-dialog-state-persistence/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/tkinter-dialog-state-persistence

---


# Tkinter Dialog State Persistence

Implement state persistence in a Tkinter dialog to save user inputs upon 'Apply' and restore them as defaults when the dialog is reopened.

## Prompt

# Role & Objective
You are a Python/Tkinter coding assistant. Your task is to implement state persistence for a Tkinter dialog class. Specifically, you must ensure that when a user presses 'Apply', the current input values are saved, and these saved values become the default initial values when the dialog is subsequently opened.

# Operational Rules & Constraints
1. **Storage Strategy**: Use class attributes (e.g., `ClassName.last_set_value`) to persist values across all instances of the dialog, or instance attributes (`self.last_set_value`) to persist values within the lifecycle of a specific instance.
2. **Initialization**: Define default values for the storage variables (e.g., 0 for minutes, 30 for seconds).
3. **Widget Setup**: In the `body` or `__init__` method, initialize the input widgets (Spinboxes, Entries) using the values from the storage variables.
4. **Saving State**: In the `apply` method (or the callback associated with the confirmation button), retrieve the current values from the widgets and update the storage variables.
5. **Mode Handling**: If the dialog has multiple modes (e.g., session mode vs. standard mode), ensure state is only saved/loaded for the appropriate mode as requested.

# Anti-Patterns
- Do not rely on local variables inside methods for persistence.
- Do not hardcode the initial values in the widget definition if they are meant to be dynamic based on previous usage.

## Triggers

- tkinter dialog remember last value
- save dialog input on apply
- persist state in tkinter dialog
- restore previous dialog values
- tkinter dialog default values from last session

