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: In tkinter, simple dialogs, askstrings, etc. with flexible coordinates and no viewable parent.
Type: enhancement Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: dominic108, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-01-01 07:21 by dominic108, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg359147 - (view) Author: Dominic Mayers (dominic108) * Date: 2020-01-01 07:21
Currently, it's not possible to center or change the coordinates in anyway of an askstring, askfloat or askinteger dialog in simpledialog.py. One can see this by looking at the code:

        if parent.winfo_viewable():
            self.transient(parent)

        if title:
            self.title(title)

        self.parent = parent

        self.result = None

        body = Frame(self)
        self.initial_focus = self.body(body)
        body.pack(padx=5, pady=5)

        self.buttonbox()

        if not self.initial_focus:
            self.initial_focus = self

        self.protocol("WM_DELETE_WINDOW", self.cancel)

        if self.parent is not None:
            self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
                                      parent.winfo_rooty()+50))

Here self.parent is never None, because the first statement would create a run time error if parent was None. So, the geometry always depends on the parent. Moreover, if the parent is not viewable, `parent.winfo_rootx()` and `parent.winfo_rooty()` are both 0. So, we can only set the coordinates of a simple dialog using a viewable parent. This contradicts a bit "simple" in "simpledialog". For example, what about an application that does not have a root window, like git for example, but, which unlike git, needs to create simple dialogs in some occasions. 

I am aware that a messagebox does not use the code that is presented above, but a messagebox is not a simple dialog - it's only a message. 

I am also aware of the class SimpleDialog, which also does not use this code, but it only works with buttons. It's not like askstring, askinteger and askfloat.
msg383768 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-25 21:51
Issue42685 improved positioning of dialog windows. Now they are centered at the parent window or screen if there is no parent. It corresponds to behavior of Tk message boxes.

Issue42721 made dialogs be usable without default root window. Temporary hidden root window can be creat3ed for the time of life of the dialog.
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83358
2020-12-25 21:51:09serhiy.storchakasetstatus: open -> closed
resolution: out of date
messages: + msg383768

stage: resolved
2020-01-12 20:32:22cheryl.sabellasetnosy: + serhiy.storchaka
2020-01-01 07:21:44dominic108create