[New-bugs-announce] [issue39177] In tkinter, simple dialogs, askstrings, etc. with flexible coordinates and no viewable parent.
report at bugs.python.org
Wed Jan 1 02:21:44 EST 2020
New submission from Dominic Mayers <dominic_mayers at yahoo.com>:
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:
self.parent = parent
self.result = None
body = Frame(self)
self.initial_focus = self.body(body)
if not self.initial_focus:
self.initial_focus = self
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.
title: In tkinter, simple dialogs, askstrings, etc. with flexible coordinates and no viewable parent.
versions: Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce