Title: In tkinter, simple dialogs, askstrings, etc. with flexible coordinates and no viewable parent.
Type: enhancement Stage:
Components: Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dominic108, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-01-01 07:21 by dominic108, last changed 2020-01-12 20:32 by cheryl.sabella.

Messages (1)
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 One can see this by looking at the code:

        if parent.winfo_viewable():

        if title:

        self.parent = parent

        self.result = None

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


        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,

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.
Date User Action Args
2020-01-12 20:32:22cheryl.sabellasetnosy: + serhiy.storchaka
2020-01-01 07:21:44dominic108create