diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-12-25 15:04:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 15:04:26 (GMT) |
commit | bb70b2afe39ad4334a9f3449cddd28149bd628b6 (patch) | |
tree | 6d86d962cf07b543fa5d25078a24bd4b9cee54ed /Lib/tkinter/__init__.py | |
parent | 954a7427ba9c2d02faed32c02090caeca873aeca (diff) | |
download | cpython-bb70b2afe39ad4334a9f3449cddd28149bd628b6.zip cpython-bb70b2afe39ad4334a9f3449cddd28149bd628b6.tar.gz cpython-bb70b2afe39ad4334a9f3449cddd28149bd628b6.tar.bz2 |
bpo-15303: Support widgets with boolean value False in Tkinter (GH-23904)
Use `widget is None` instead of checking the boolean value of a widget.
Diffstat (limited to 'Lib/tkinter/__init__.py')
-rw-r--r-- | Lib/tkinter/__init__.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 1cc1870..a32eb76 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -292,7 +292,7 @@ def _get_default_root(what=None): if not _support_default_root: raise RuntimeError("No master specified and tkinter is " "configured to not support default root") - if not _default_root: + if _default_root is None: if what: raise RuntimeError(f"Too early to {what}: no default root window") root = Tk() @@ -342,7 +342,7 @@ class Variable: if name is not None and not isinstance(name, str): raise TypeError("name must be a string") global _varnum - if not master: + if master is None: master = _get_default_root('create variable') self._root = master._root() self._tk = master.tk @@ -808,7 +808,7 @@ class Misc: function which shall be called. Additional parameters are given as parameters to the function call. Return identifier to cancel scheduling with after_cancel.""" - if not func: + if func is None: # I'd rather use time.sleep(ms*0.001) self.tk.call('after', ms) return None @@ -1542,7 +1542,7 @@ class Misc: def _root(self): """Internal function.""" w = self - while w.master: w = w.master + while w.master is not None: w = w.master return w _subst_format = ('%#', '%b', '%f', '%h', '%k', '%s', '%t', '%w', '%x', '%y', @@ -2306,7 +2306,7 @@ class Tk(Misc, Wm): self.tk.createcommand('exit', _exit) self._tclCommands.append('tkerror') self._tclCommands.append('exit') - if _support_default_root and not _default_root: + if _support_default_root and _default_root is None: _default_root = self self.protocol("WM_DELETE_WINDOW", self.destroy) @@ -2534,7 +2534,7 @@ class BaseWidget(Misc): def _setup(self, master, cnf): """Internal function. Sets up information about children.""" - if not master: + if master is None: master = _get_default_root() self.master = master self.tk = master.tk @@ -3949,7 +3949,7 @@ class _setit: def __call__(self, *args): self.__var.set(self.__value) - if self.__callback: + if self.__callback is not None: self.__callback(self.__value, *args) @@ -3998,7 +3998,7 @@ class Image: def __init__(self, imgtype, name=None, cnf={}, master=None, **kw): self.name = None - if not master: + if master is None: master = _get_default_root('create image') self.tk = getattr(master, 'tk', master) if not name: |