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: make X window & macOS recognize dialogs as such
Type: enhancement Stage: resolved
Components: IDLE, Tkinter Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: epaine, miss-islington, patrickmelix, serhiy.storchaka, taleinat, terry.reedy
Priority: normal Keywords: patch

Created on 2021-03-29 08:53 by patrickmelix, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25061 closed patrickmelix, 2021-03-29 08:55
PR 25187 merged serhiy.storchaka, 2021-04-04 17:53
PR 25588 merged serhiy.storchaka, 2021-04-25 10:13
PR 25592 merged miss-islington, 2021-04-25 10:49
Messages (12)
msg389676 - (view) Author: Patrick Melix (patrickmelix) * Date: 2021-03-29 08:53
While trying to fix window behaviour in a python project (ASE: https://wiki.fysik.dtu.dk/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
```self.top.wm_attributes('-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 https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm, (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 https://wiki.tcl-lang.org/page/MacWindowStyle . 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.
msg391847 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-25 10:08
New changeset 3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c by Serhiy Storchaka in branch 'master':
bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (#25187)
https://github.com/python/cpython/commit/3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c
msg391854 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-25 10:49
New changeset 9a165399aec930f27639dd173426ccc33586662b by Serhiy Storchaka in branch '3.9':
[3.9] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (GH-25187). (GH-25588)
https://github.com/python/cpython/commit/9a165399aec930f27639dd173426ccc33586662b
msg391855 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-25 11:19
New changeset 6077efa2b2be17e736d061fe74f933dc616c64b2 by Miss Islington (bot) in branch '3.8':
[3.9] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (GH-25187). (GH-25588) (GH-25592)
https://github.com/python/cpython/commit/6077efa2b2be17e736d061fe74f933dc616c64b2
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87821
2021-04-25 11:20:20serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-25 11:19:55serhiy.storchakasetmessages: + msg391855
2021-04-25 10:49:40miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24312
2021-04-25 10:49:35serhiy.storchakasetmessages: + msg391854
2021-04-25 10:13:13serhiy.storchakasetpull_requests: + pull_request24307
2021-04-25 10:08:02serhiy.storchakasetmessages: + msg391847
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