Skip to content

Conversation

@Impaler343
Copy link
Contributor

@Impaler343 Impaler343 commented Dec 13, 2025

PR summary

Following up on Issue #14081 regarding removal of focus_set() parameter call in the __init__() function of FigureCanvasTkAgg. Observed a similar focus structure in FigureFrameWx

Interestingly, I'm unable to reproduce the issue. Even after running a script I only get the output -> .!button, so I'm unable to gauge the importance of the fix. This could also be due to an upstream fix in Tkinter but that seems unlikely.

I'm also unsure of where (or if) to document the change in behavior other than the release notes. Standard Tk widgets do not grab focus on creation, so this change would align the canvas with standard behavior.

I have also thought a great deal about the deprecation process. Any logical way to warn the user seems too noisy for FigureCanvasTkAgg. An unsuspecting user would receive a warning about focus changes even if they had no intention of interacting with the focus mechanism. (As the warning would have to be part of the __init__() )

Updated and Enhanced test_backend_tk::test_canvas_focus to handle three cases:

  • Canvas created and packed to top-level widget (Focus - No)
  • Canvas created, packed and focus set manually (Focus - Yes)
    • (Using focus_force() instead of focus_set() as MacOS tests fail with the latter)
  • Canvas created, packed and shown using plt.show() (Focus - Yes)

Added @daniilS as Co-Author for initial ideas

PR checklist

Co-authored-by: daniilS <daniil.soloviev@gmail.com>
@Impaler343 Impaler343 marked this pull request as ready for review December 13, 2025 17:02
@timhoffm
Copy link
Member

timhoffm commented Dec 14, 2025

I'm not clear on the exact way forward here, but per #14081 (comment) ("other embedding users will suddenly have to set the focus manually or never receive those keypress/keyrelease events") I don't think we can do a hard switch as implemented in this PR.

We need to define what exactly we want to do. I've added #14081 (comment) as a basis for discussion.

@timhoffm timhoffm added the status: needs comment/discussion needs consensus on next step label Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: examples files in galleries/examples GUI: tk status: needs comment/discussion needs consensus on next step

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FigureCanvasTkAgg.__init__ steals focus

2 participants