fix: import tkinter.messagebox explicitly in ui.py - #2
Open
rsmxingu wants to merge 1 commit into
Open
Conversation
ui.py called tk.messagebox.* (showwarning/askyesno/showerror/showinfo) but only imported `tkinter as tk`. tkinter.messagebox is a submodule that is NOT loaded by `import tkinter`; it only resolves if some other module imported it first. That made the dialogs (no-file-selected warning, cancel confirmation, success/error popups) depend on an implicit, unguaranteed import — an AttributeError waiting to happen depending on customtkinter/Python version. Import messagebox explicitly via `from tkinter import filedialog, messagebox` and call messagebox.* directly so the dependency is real and obvious. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ui.pycallstk.messagebox.*in five places (no-file warning, no-image warning, cancel confirmation, error popup, success popup) but only importstkinter as tk.tkinter.messageboxis a submodule — it is not loaded byimport tkinter. The attributetk.messageboxonly resolves if some other already-imported module happened to import it first (e.g. customtkinter, on some versions). This makes every dialog anAttributeErrorwaiting to happen, depending on the customtkinter/Python version in use.Affected call sites (
ui.py):on_optimize_clicked→showwarning(no file / no intro image)on_cancel_clicked→askyesnoupdate_progress→showerror/showinfoChange
Import the submodule explicitly and call it directly:
Now the dependency is real and explicit rather than relying on an incidental import.
Testing
python3 -m py_compile ui.pypasses.tests/test_ui.pymocks customtkinter and tkinter and does not exercise messagebox, so it is unaffected.)🤖 Generated with Claude Code