Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-39171: Missing root in tkinter simpledialog.py _QueryDialog#17775

Closed
Dominic-Mayers wants to merge 2 commits into
python:masterpython/cpython:masterfrom
Dominic-Mayers:masterCopy head branch name to clipboard
Closed

bpo-39171: Missing root in tkinter simpledialog.py _QueryDialog#17775
Dominic-Mayers wants to merge 2 commits into
python:masterpython/cpython:masterfrom
Dominic-Mayers:masterCopy head branch name to clipboard

Conversation

@Dominic-Mayers

@Dominic-Mayers Dominic-Mayers commented Dec 31, 2019

Copy link
Copy Markdown

My first pull request. I hope this will be obviously linked to https://bugs.python.org/issue39171.

https://bugs.python.org/issue39171

@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@MaharishiCanada

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@Dominic-Mayers

Copy link
Copy Markdown
Author

I signed the CLA and added a blurb. I hope these are OK now.

* The programmer has to create the root himself and then withdraw it.
* In a similar situation, the moduke ttk creates the root automatically.

if not parent:
parent = tkinter._default_root
if tkinter._default_root:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend changing this to an explicit check for "not None"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The only reason why I did not do it, is to make as little change as possible.

parent = tkinter._default_root
elif tkinter._support_default_root:
parent = tkinter.Tk()
parent.withdraw()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a new Tk instance is being created, I am of the opinion it should be explicitly deleted once we are done with the dialog (we shouldn't rely on the GC to clean it).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, would it be better to mimic tkinter.commondialog (for consistency), which doesn't withdraw or delete a new window?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that too. It was a few months ago, but I remember to have compared with what is done elsewhere and came to the same conclusion.

@@ -0,0 +1 @@
Creating missing parent in tkinter simpledialog when possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be better suited to the "library" part of the news?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about these aspects.

@E-Paine

E-Paine commented Jun 16, 2020

Copy link
Copy Markdown
Contributor

I really appreciate the effort that has clearly gone into this patch, however I fear it is needlessly over-complicated. It may be better to set the parent to a dummy frame, similar to 'commondialog', which will then handle all your logic in a single line (parent = Frame(parent) - though you would want to rename one of those "parent"s for clarity).

@Dominic-Mayers

Copy link
Copy Markdown
Author

It is not clear to me that it will be equivalent. I suspect that to have the expected behavior with regard to the location of the widget, one may want to reuse the current main window, if it exists. Honestly, the current code is something that I wrote few months ago, so I am relying on vague memory, but what I recall is that location with respect to the current parent was important. But, if you are sure that you are taking care of all the logic with respect to location, go ahead.

@E-Paine

E-Paine commented Jun 16, 2020

Copy link
Copy Markdown
Contributor

Sorry, by a dummy widget, I meant create a blank frame but not add it to the window. This way the window supplied by "parent" is used if it exists, otherwise the default root and falling back to create a new window. The widget is never added to the window using a display manager.
Unfortunately I cannot make changes to your branch as I am not a core-dev, but the changes would only be to remove all if not parent: code (including the if statement) and replace it with parent = Frame(parent).
As for the change to the news entry, the file could just be moved to Misc/NEWS.d/next/Library/2019-12-31-19-06-02.bpo-39171.cmXDsX.rst with no changes required to the content ("Core and Builtins" is generally for changes to the Python interpreter)

@Dominic-Mayers

Copy link
Copy Markdown
Author

I propose this for the news: Creating missing parent in tkinter simpledialog when possible. Patch by E-Paine and MaharishiCanada. I will use parent = Frame(parent) as you suggest for the revised patch. It makes plenty of sense that this will reuse the parent if it exists. I'll also check the behavior with the use case I have in mind.

@serhiy-storchaka

Copy link
Copy Markdown
Member

It was done in more general way in other issues.

@Dominic-Mayers

Copy link
Copy Markdown
Author

Great !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.