mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[3.9] bpo-42630: Improve error reporting in Tkinter for absent default root (GH-23781) (GH-23853)
* 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.
(cherry picked from commit 3d569fd6dc
)
This commit is contained in:
parent
d458d8dab0
commit
87e7a14ee3
19 changed files with 316 additions and 87 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue