-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-42630: Improve error reporting in Tkinter for absent default root #23781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f43855a
98a47b9
ba335c6
c5db1f7
6284e46
0a5db85
7209007
70dd5c9
007c61f
2d2c89f
9b31415
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -69,7 +69,7 @@ def _mkdict(self, args): | |||||
def __init__(self, root=None, font=None, name=None, exists=False, | ||||||
**options): | ||||||
if not root: | ||||||
root = tkinter._default_root | ||||||
root = tkinter._get_default_root('use font') | ||||||
tk = getattr(root, 'tk', root) | ||||||
if font: | ||||||
# get actual settings corresponding to the given font | ||||||
|
@@ -184,7 +184,7 @@ def metrics(self, *options, **kw): | |||||
def families(root=None, displayof=None): | ||||||
"Get font families (as a tuple)" | ||||||
if not root: | ||||||
root = tkinter._default_root | ||||||
root = tkinter._get_default_root('use font.families()') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Similar to what you did in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code differs from the code in
It is larger change of code and I am not sure it is worth. |
||||||
args = () | ||||||
if displayof: | ||||||
args = ('-displayof', displayof) | ||||||
|
@@ -194,7 +194,7 @@ def families(root=None, displayof=None): | |||||
def names(root=None): | ||||||
"Get names of defined fonts (as a tuple)" | ||||||
if not root: | ||||||
root = tkinter._default_root | ||||||
root = tkinter._get_default_root('use font.names()') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See above comment. |
||||||
return root.tk.splitlist(root.tk.call("font", "names")) | ||||||
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,33 @@ def tearDown(self): | |
w.destroy() | ||
self.root.withdraw() | ||
|
||
|
||
class AbstractDefaultRootTest: | ||
|
||
def setUp(self): | ||
self._old_support_default_root = tkinter._support_default_root | ||
destroy_default_root() | ||
tkinter._support_default_root = True | ||
self.wantobjects = tkinter.wantobjects | ||
|
||
def tearDown(self): | ||
destroy_default_root() | ||
tkinter._default_root = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this, as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not do it if |
||
tkinter._support_default_root = self._old_support_default_root | ||
|
||
def _test_widget(self, constructor): | ||
# no master passing | ||
x = constructor() | ||
self.assertIsNotNone(tkinter._default_root) | ||
self.assertIs(x.master, tkinter._default_root) | ||
self.assertIs(x.tk, tkinter._default_root.tk) | ||
x.destroy() | ||
destroy_default_root() | ||
tkinter.NoDefaultRoot() | ||
self.assertRaises(RuntimeError, constructor) | ||
self.assertFalse(hasattr(tkinter, '_default_root')) | ||
|
||
|
||
def destroy_default_root(): | ||
if getattr(tkinter, '_default_root', None): | ||
tkinter._default_root.update_idletasks() | ||
|
Uh oh!
There was an error while loading. Please reload this page.