Title: Tkinter: make X window & macOS recognize dialogs as such
Type: enhancement Stage: patch review
Components: IDLE, Tkinter Versions: Python 3.10, Python 3.9, Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: epaine, patrickmelix, serhiy.storchaka, taleinat, terry.reedy
Priority: normal Keywords: patch

Created on 2021-03-29 08:53 by patrickmelix, last changed 2021-04-04 21:26 by terry.reedy.

Pull Requests
URL Status Linked Edit
PR 25061 closed patrickmelix, 2021-03-29 08:55
PR 25187 open serhiy.storchaka, 2021-04-04 17:53
Messages (9)
msg389676 - (view) Author: Patrick Melix (patrickmelix) * Date: 2021-03-29 08:53
While trying to fix window behaviour in a python project (ASE:, I came across this problem:

Tkinter does not set the _NET_WM_WINDOW_TYPE when using the FileDialog class or it's derivatives. I could not find a reason for this and it leads to my window manager (i3) not automatically recognising the window as a dialogue (and thus not enabling floating). I think the window types are there exactly for that purpose, so I don't see why not to set this as the default for the FileDialog class.

I was able to change this by adding the line
```'-type', 'dialog')```
to the initialization of the FileDialog class. See also MR on GitHub.

Since I am an absolute beginner at this please do forgive if I missed something.
msg389681 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-03-29 09:48
Thank you for your report and PR Patrick.

I agree, it would be better to to set the "type" attribute to "dialog" for the FileDialog window. Tk does it for its dialog windows. But it is more complex.

* It should be set not only for FileDialog, but for other dialog windows implemented in Python too (including dialog windows specific for IDLE). I am in process of working on making dialog windows implemented in Python looking and behaving closer to dialog windows implemented in Tk. The hardest part is writing tests for this.

* This code should be executed only on X Window. On macOS and Windows different code is needed. From Tk sources of ::tk::dialog::file::Create and ::tk::dialog::color:: :

    if {[tk windowingsystem] eq "x11"} {wm attributes $w -type dialog}

And in ::tk_dialog and ::tk::MessageBox :

    if {$windowingsystem eq "aqua"} {
        ::tk::unsupported::MacWindowStyle style $w moveableModal {}
    } elseif {$windowingsystem eq "x11"} {
        wm attributes $w -type dialog

And ::tk::dialog::error::bgerror uses moveableAlert instead of moveableModal.
msg389683 - (view) Author: Patrick Melix (patrickmelix) * Date: 2021-03-29 10:33
Thank you for your feedback Serhiy!

I obviously totally forgot about compatibility issues with other OS... If you are already aware of this and working on a solution even better. Did I miss this during my search or is it not public anywhere yet?

For now one can easily avoid the issue by always setting the type manually, will have to see how to avoid the OS issue you mention then.

Perhaps you can point me to the place to watch for your progress on the matter so I can keep track of this?
Thanks again!
msg389862 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-03-30 21:53
No, it is not ready for publishing yet. I'll try to work on it on the next weekend. Since it is a large change, there is a risk of breaking user code, so perhaps it would be worth to separate changes related to this issue which can be backported.
msg390204 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-04 18:04
PR 25187 makes all Tkinter dialog windows and most IDLE dialog windows (except about and help windows) be recognized as dialogs by window managers on macOS and X Window. It conforms the behavior of standard Tk dialog windows.

This change is harmless enough to be backported.
msg390209 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-04-04 19:24
Epaine (or Tal?): please test PR-25187 on Mac.
msg390210 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-04-04 20:08
I presume 'floatable' means 'can move dialog around on top of the parent window'.  On my Mac Air, with 3.8 and 8.6.8, all the dialogs I checked, including About, are already floatable in this sense, not just the search boxes (which already had "::tk::unsupported::MacWindowsStyle" call).  Since tk::unsupported is not listed on, (nor on the 8.5 page) I wonder if it is obsolete, or just hidden.

If no one knows, we might ask Kevin Walzer.
msg390215 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-04 21:17
See . I suppose it affects window decoration.
msg390216 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-04-04 21:26
Excuse me, it is the query boxes, not the search boxes, that already have the call.  Unlike the other boxes I initially tested, they do not have the traffic lights.  I believe that this, not movability, is the effect on mac of 'movableModal'.  I tested a messagebox and it also had no traffic lights.

What effect does the change have on Linux?

On my MacBook, IDLE preferences is too tall, so that the bottom buttons are not visible and the only way to reliably cancel is to click the red button on the title bar.  So remove the change for that at least until we have redesigned the dialog to be wide instead of tall.  There is also an IDLE issue questioning whether Preferences (and Search) should even be modal.

Currently, IDLE file open and save-as drop down from the center of title bar, have no traffic lights, and cannot be moved.  Open is the entire width of the screen and could only go up and down.  For Open, the underlying window is moved to the center.  For Safari, Save as is the same, so I question whether it should be changed.  Safari's Open is movable.  Neither window for either app currently has traffic lights.
Date User Action Args
2021-04-04 21:26:52terry.reedysetmessages: + msg390216
2021-04-04 21:17:39serhiy.storchakasetmessages: + msg390215
2021-04-04 20:08:48terry.reedysetmessages: + msg390210
2021-04-04 19:24:31terry.reedysetnosy: + epaine

messages: + msg390209
title: Tkinter: Not setting _NET_WM_WINDOW_TYPE on FileDialog -> Tkinter: make X window & macOS recognize dialogs as such
2021-04-04 18:04:05serhiy.storchakasetnosy: + terry.reedy, taleinat
messages: + msg390204

assignee: terry.reedy
components: + IDLE
2021-04-04 17:53:48serhiy.storchakasetpull_requests: + pull_request23929
2021-03-30 21:53:33serhiy.storchakasetmessages: + msg389862
versions: - Python 3.6, Python 3.7
2021-03-29 10:33:45patrickmelixsetmessages: + msg389683
2021-03-29 09:48:53serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg389681
2021-03-29 08:55:09patrickmelixsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23810
2021-03-29 08:53:43patrickmelixcreate