Skip to content

Fix NameError in choose_bg_color when color picker is cancelled - #84

Merged
petertzy merged 1 commit into
petertzy:mainfrom
apoorvdarshan:fix/choose-bg-color-nameerror
Feb 18, 2026
Merged

petertzy merged 1 commit into
petertzy:mainfrom
apoorvdarshan:fix/choose-bg-color-nameerror

Conversation

@apoorvdarshan

@apoorvdarshan apoorvdarshan commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Bug: Cancelling the background color picker dialog causes a NameError crash because text_area is only defined inside the if color: block but referenced outside it on the next line.
  • Fix: Nest the text_area check inside the if color: block, matching the pattern already used by choose_fg_color().

Before (buggy)

if color:
    color = color.hex
    text_area = self.get_current_text_area()
if text_area:  # NameError if color is None
    text_area.config(bg=color)

After (fixed)

if color:
    color = color.hex
    text_area = self.get_current_text_area()
    if text_area:
        text_area.config(bg=color)
        self.current_bg_color = color
        self.update_preview()

Test plan

  • Open the app, go to background color picker, cancel the dialog — should no longer crash
  • Choose a valid color — should still apply correctly
When a user cancels the color chooser dialog, text_area was referenced
outside the if color: block where it was defined, causing a NameError.
Fixed by nesting the text_area usage inside the color check, matching
the pattern already used in choose_fg_color.
@apoorvdarshan
apoorvdarshan force-pushed the fix/choose-bg-color-nameerror branch from aeb1f3a to 002ebec Compare February 17, 2026 16:32
@petertzy
petertzy merged commit f98ead6 into petertzy:main Feb 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants