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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion 10 Lib/tkinter/simpledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,15 @@ def __init__(self, title, prompt,
parent = None):

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.

else:
raise RuntimeError(
"No parent specified and tkinter is "
"configured to not support default root")

self.prompt = prompt
self.minvalue = minvalue
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

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