summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter/simpledialog.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-12-19 10:17:08 (GMT)
committerGitHub <noreply@github.com>2020-12-19 10:17:08 (GMT)
commit3d569fd6dccf9f582bafaca04d3535094cae393e (patch)
tree2468e1823c476391b2abecc79d093e0cbeb96b0c /Lib/tkinter/simpledialog.py
parent1e27b57dbc8c1b758e37a531487813aef2d111ca (diff)
downloadcpython-3d569fd6dccf9f582bafaca04d3535094cae393e.zip
cpython-3d569fd6dccf9f582bafaca04d3535094cae393e.tar.gz
cpython-3d569fd6dccf9f582bafaca04d3535094cae393e.tar.bz2
bpo-42630: Improve error reporting in Tkinter for absent default root (GH-23781)
* Tkinter functions and constructors which need a default root window raise now RuntimeError with descriptive message instead of obscure AttributeError or NameError if it is not created yet or cannot be created automatically. * Add tests for all functions which use default root window. * Fix import in the pynche script.
Diffstat (limited to 'Lib/tkinter/simpledialog.py')
-rw-r--r--Lib/tkinter/simpledialog.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py
index 8524417..b882d47 100644
--- a/Lib/tkinter/simpledialog.py
+++ b/Lib/tkinter/simpledialog.py
@@ -24,9 +24,7 @@ askstring -- get a string from the user
"""
from tkinter import *
-from tkinter import messagebox
-
-import tkinter # used at _QueryDialog for tkinter._default_root
+from tkinter import messagebox, _get_default_root
class SimpleDialog:
@@ -128,13 +126,17 @@ class Dialog(Toplevel):
title -- the dialog title
'''
- Toplevel.__init__(self, parent)
+ master = parent
+ if not master:
+ master = _get_default_root('create dialog window')
+
+ Toplevel.__init__(self, master)
self.withdraw() # remain invisible for now
- # If the master is not viewable, don't
+ # If the parent is not viewable, don't
# make the child transient, or else it
# would be opened withdrawn
- if parent.winfo_viewable():
+ if parent is not None and parent.winfo_viewable():
self.transient(parent)
if title:
@@ -155,7 +157,7 @@ class Dialog(Toplevel):
self.protocol("WM_DELETE_WINDOW", self.cancel)
- if self.parent is not None:
+ if parent is not None:
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
parent.winfo_rooty()+50))
@@ -259,9 +261,6 @@ class _QueryDialog(Dialog):
minvalue = None, maxvalue = None,
parent = None):
- if not parent:
- parent = tkinter._default_root
-
self.prompt = prompt
self.minvalue = minvalue
self.maxvalue = maxvalue