Skip to content

Fix Windows title menu lifecycle bugs and preserve host Configure bin…#50

Open
sherpya wants to merge 1 commit intoAkascape:mainfrom
sherpya:titlemenu-lifecycle-fix
Open

Fix Windows title menu lifecycle bugs and preserve host Configure bin…#50
sherpya wants to merge 1 commit intoAkascape:mainfrom
sherpya:titlemenu-lifecycle-fix

Conversation

@sherpya
Copy link
Copy Markdown

@sherpya sherpya commented Mar 25, 2026

Summary

Fix CTkTitleMenu lifecycle issues on Windows.

This change prevents stale master callbacks from firing after the title menu has been destroyed, and avoids overwriting existing master event bindings.

Problem

CTkTitleMenu currently binds master events like this:

self.master.bind("<Configure>", lambda _: self.change_dimension())
self.master.bind("<Destroy>", lambda _: self.destroy_window() if not self.master.winfo_viewable() else None)
self.master.bind("<Map>", lambda e: self.withdraw)

This causes a few issues:

  • master bindings are overwritten because add="+" is not used
  • callbacks remain attached after the title menu is destroyed
  • later <Configure> events may call change_dimension() on a destroyed CTkTitleMenu, raising:
    TclError: bad window path name ".!ctktitlemenu"
  • the <Map> callback returns self.withdraw instead of actually calling self.withdraw()

Changes

  • bind <Configure>, <Destroy>, and <Map> with add="+"
  • store binding ids
  • unbind master callbacks in destroy() / destroy_window()
  • guard change_dimension() against destroyed widgets
  • fix the <Map> callback to actually call withdraw()

Result

CTkTitleMenu no longer leaves stale callbacks behind after destruction, and it no longer clobbers other master event handlers.

Optional note

Tested locally on Windows with a CustomTkinter app using CTkTitleMenu.

@sherpya sherpya force-pushed the titlemenu-lifecycle-fix branch from 5bdf92b to d3e4665 Compare March 26, 2026 11:37
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