Skip to content

fix: import tkinter.messagebox explicitly in ui.py - #2

Open
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:fix/messagebox-import
Open

fix: import tkinter.messagebox explicitly in ui.py#2
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:fix/messagebox-import

Conversation

@rsmxingu

Copy link
Copy Markdown

Problem

ui.py calls tk.messagebox.* in five places (no-file warning, no-image warning, cancel confirmation, error popup, success popup) but only imports tkinter as tk.

tkinter.messagebox is a submodule — it is not loaded by import tkinter. The attribute tk.messagebox only resolves if some other already-imported module happened to import it first (e.g. customtkinter, on some versions). This makes every dialog an AttributeError waiting to happen, depending on the customtkinter/Python version in use.

Affected call sites (ui.py):

  • on_optimize_clickedshowwarning (no file / no intro image)
  • on_cancel_clickedaskyesno
  • update_progressshowerror / showinfo

Change

Import the submodule explicitly and call it directly:

from tkinter import filedialog, messagebox
...
messagebox.showwarning(...)  # instead of tk.messagebox.showwarning(...)

Now the dependency is real and explicit rather than relying on an incidental import.

Testing

  • python3 -m py_compile ui.py passes.
  • Behavior of the dialogs is unchanged; only the import path is made correct.
  • (The repo's tests/test_ui.py mocks customtkinter and tkinter and does not exercise messagebox, so it is unaffected.)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant