This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter- On windows, calling filedialog or messagebox before the window is drawn causes focus issues
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: nyt, serhiy.storchaka, terry.reedy, wordtech
Priority: normal Keywords:

Created on 2018-07-27 23:28 by nyt, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg322516 - (view) Author: Novel (nyt) Date: 2018-07-27 23:28
Code to reproduce the problem: 

```
import tkinter as tk
from tkinter.messagebox import showinfo

root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
# root.update() # remove comment to fix the problem
showinfo('alert', 'this parrot is dead!')
root.mainloop()
```

Running this code will show the alert, and when the user clicks "ok" the entry widget acts as if it's disabled and won't focus. Minimizing and restoring the tkinter window brings the entry widget back to normal operation. 

Workaround: Calling `update()` before the messagebox or filedialog call gives normal behaviour. 

This issue only affects Windows as far as I can tell.
msg323064 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-08-03 19:27
You only need to run .update_idletasks(), as there are no pending events to process.

This is not a tkinter issue.  It is a known fact that there are undocumented annoying differences in tk behavior on different systems and even different versions thereof.  In #34275, for instance, we had to add .update_idletasks for IDLE calltips to appear on Macs with recent tk versions.

For Windows, your code also needs entry.focus_set to be able to enter text, after the mbox is dismissed, without activating the widget with a click.

Indeed, the call is needed here on Mac with Python 3.7.0 and tk 8.6.8.  Without it, the root window partially keeps the focus, in that the traffic lights remain light, and the messagebox only partially get the focus, in that the title and OK button are dimmed.  One has to click on the box to highlight the title and OK.  With the call, the root lights go out and the box is active, and can be dismissed with <Enter>.

There is an additional issue on current Mac.  When the mbox is dismissed, focus does not return properly to the root and entry.  They have to be clicked on.  Since this is similar to the problem in #34120, and since Novel's issue on Windows is exactly like the 'have to go away and come back' part of #34120, I wonder if the model mbox needs an explicit grab release.

Kevin, since the mbox is created and destroyed within a call to the tk messageBox function we have no control of its operation.  Perhaps you could check the tcl/tk code and see it if needs updating, as did the IDLE code.
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78434
2018-08-03 19:27:16terry.reedysetstatus: open -> closed

type: behavior

nosy: + wordtech, terry.reedy, serhiy.storchaka
messages: + msg323064
resolution: third party
stage: resolved
2018-07-27 23:28:13nytcreate