Skip to content
Merged
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
16 changes: 8 additions & 8 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -342,7 +342,7 @@ def __init__(self, master=None, value=None, name=None):
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
Expand Down Expand Up @@ -808,7 +808,7 @@ def after(self, ms, func=None, *args):
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
Expand Down Expand Up @@ -1542,7 +1542,7 @@ def _register(self, func, subst=None, needcleanup=1):
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',
Expand Down Expand Up @@ -2306,7 +2306,7 @@ def _loadtk(self):
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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3949,7 +3949,7 @@ def __init__(self, var, value, callback=None):

def __call__(self, *args):
self.__var.set(self.__value)
if self.__callback:
if self.__callback is not None:
self.__callback(self.__value, *args)


Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/commondialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Dialog:
command = None

def __init__(self, master=None, **options):
if not master:
if master is None:
master = options.get('parent')
self.master = master
self.options = options
Expand Down
22 changes: 11 additions & 11 deletions Lib/tkinter/dnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

def dnd_start(source, event):
h = DndHandler(source, event)
if h.root:
if h.root is not None:
return h
else:
return None
Expand Down Expand Up @@ -143,7 +143,7 @@ def __init__(self, source, event):
def __del__(self):
root = self.root
self.root = None
if root:
if root is not None:
try:
del root.__dnd
except AttributeError:
Expand All @@ -154,25 +154,25 @@ def on_motion(self, event):
target_widget = self.initial_widget.winfo_containing(x, y)
source = self.source
new_target = None
while target_widget:
while target_widget is not None:
try:
attr = target_widget.dnd_accept
except AttributeError:
pass
else:
new_target = attr(source, event)
if new_target:
if new_target is not None:
break
target_widget = target_widget.master
old_target = self.target
if old_target is new_target:
if old_target:
if old_target is not None:
old_target.dnd_motion(source, event)
else:
if old_target:
if old_target is not None:
self.target = None
old_target.dnd_leave(source, event)
if new_target:
if new_target is not None:
new_target.dnd_enter(source, event)
self.target = new_target

Expand All @@ -193,7 +193,7 @@ def finish(self, event, commit=0):
self.initial_widget.unbind("<Motion>")
widget['cursor'] = self.save_cursor
self.target = self.source = self.initial_widget = self.root = None
if target:
if target is not None:
if commit:
target.dnd_commit(source, event)
else:
Expand All @@ -215,9 +215,9 @@ def attach(self, canvas, x=10, y=10):
if canvas is self.canvas:
self.canvas.coords(self.id, x, y)
return
if self.canvas:
if self.canvas is not None:
self.detach()
if not canvas:
if canvas is None:
return
label = tkinter.Label(canvas, text=self.name,
borderwidth=2, relief="raised")
Expand All @@ -229,7 +229,7 @@ def attach(self, canvas, x=10, y=10):

def detach(self):
canvas = self.canvas
if not canvas:
if canvas is None:
return
id = self.id
label = self.label
Expand Down
6 changes: 3 additions & 3 deletions Lib/tkinter/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _mkdict(self, args):

def __init__(self, root=None, font=None, name=None, exists=False,
**options):
if not root:
if root is None:
root = tkinter._get_default_root('use font')
tk = getattr(root, 'tk', root)
if font:
Expand Down Expand Up @@ -183,7 +183,7 @@ def metrics(self, *options, **kw):

def families(root=None, displayof=None):
"Get font families (as a tuple)"
if not root:
if root is None:
root = tkinter._get_default_root('use font.families()')
args = ()
if displayof:
Expand All @@ -193,7 +193,7 @@ def families(root=None, displayof=None):

def names(root=None):
"Get names of defined fonts (as a tuple)"
if not root:
if root is None:
root = tkinter._get_default_root('use font.names()')
return root.tk.splitlist(root.tk.call("font", "names"))

Expand Down
4 changes: 2 additions & 2 deletions Lib/tkinter/simpledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, parent, title = None):
title -- the dialog title
'''
master = parent
if not master:
if master is None:
master = _get_default_root('create dialog window')

Toplevel.__init__(self, master)
Expand All @@ -152,7 +152,7 @@ def __init__(self, parent, title = None):

self.buttonbox()

if not self.initial_focus:
if self.initial_focus is None:
self.initial_focus = self

self.protocol("WM_DELETE_WINDOW", self.cancel)
Expand Down
6 changes: 3 additions & 3 deletions Lib/tkinter/tix.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def config_all(self, option, value):
self.tk.call(name, 'configure', '-' + option, value)
# These are missing from Tkinter
def image_create(self, imgtype, cnf={}, master=None, **kw):
if not master:
if master is None:
master = self
if kw and cnf: cnf = _cnfmerge((cnf, kw))
elif kw: cnf = kw
Expand Down Expand Up @@ -467,7 +467,7 @@ class DisplayStyle:
(multiple) Display Items"""

def __init__(self, itemtype, cnf={}, *, master=None, **kw):
if not master:
if master is None:
if 'refwindow' in kw:
master = kw['refwindow']
elif 'refwindow' in cnf:
Expand Down Expand Up @@ -862,7 +862,7 @@ def add(self, entry, cnf={}, **kw):
return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))

def add_child(self, parent=None, cnf={}, **kw):
if not parent:
if parent is None:
parent = ''
return self.tk.call(
self._w, 'addchild', parent, *self._options(cnf, kw))
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def instate(self, statespec, callback=None, *args, **kw):
matches statespec. statespec is expected to be a sequence."""
ret = self.tk.getboolean(
self.tk.call(self._w, "instate", ' '.join(statespec)))
if ret and callback:
if ret and callback is not None:
return callback(*args, **kw)

return ret
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`tkinter` supports now widgets with boolean value False.