diff -r 3c830691f598 Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/__init__.py Sun Dec 23 20:52:21 2012 +0200 @@ -180,7 +180,7 @@ 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 = _default_root self._master = master self._tk = master.tk @@ -496,7 +496,7 @@ 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) else: @@ -1138,7 +1138,7 @@ 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', @@ -1792,7 +1792,7 @@ 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) def destroy(self): @@ -2009,8 +2009,8 @@ """Internal function. Sets up information about children.""" if _support_default_root: global _default_root - if not master: - if not _default_root: + if master is None: + if _default_root is None: _default_root = Tk() master = _default_root self.master = master @@ -3228,7 +3228,7 @@ self.__callback = callback def __call__(self, *args): self.__var.set(self.__value) - if self.__callback: + if self.__callback is not None: self.__callback(self.__value, *args) class OptionMenu(Menubutton): @@ -3273,9 +3273,9 @@ _last_id = 0 def __init__(self, imgtype, name=None, cnf={}, master=None, **kw): self.name = None - if not master: + if master is None: master = _default_root - if not master: + if master is None: raise RuntimeError('Too early to create image') self.tk = master.tk if not name: diff -r 3c830691f598 Lib/tkinter/commondialog.py --- a/Lib/tkinter/commondialog.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/commondialog.py Sun Dec 23 20:52:21 2012 +0200 @@ -22,7 +22,7 @@ self.master = master self.options = options - if not master and options.get('parent'): + if master is None and options.get('parent'): self.master = options['parent'] def _fixoptions(self): diff -r 3c830691f598 Lib/tkinter/dnd.py --- a/Lib/tkinter/dnd.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/dnd.py Sun Dec 23 20:52:21 2012 +0200 @@ -107,7 +107,7 @@ def dnd_start(source, event): h = DndHandler(source, event) - if h.root: + if h.root is not None: return h else: return None @@ -142,7 +142,7 @@ def __del__(self): root = self.root self.root = None - if root: + if root is not None: try: del root.__dnd except AttributeError: @@ -153,25 +153,25 @@ 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 @@ -192,7 +192,7 @@ self.initial_widget.unbind("") 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: @@ -215,9 +215,9 @@ 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") @@ -229,7 +229,7 @@ def detach(self): canvas = self.canvas - if not canvas: + if canvas is None: return id = self.id label = self.label diff -r 3c830691f598 Lib/tkinter/font.py --- a/Lib/tkinter/font.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/font.py Sun Dec 23 20:52:21 2012 +0200 @@ -67,7 +67,7 @@ def __init__(self, root=None, font=None, name=None, exists=False, **options): - if not root: + if root is None: root = tkinter._default_root if font: # get actual settings corresponding to the given font @@ -178,7 +178,7 @@ def families(root=None, displayof=None): "Get font families (as a tuple)" - if not root: + if root is None: root = tkinter._default_root args = () if displayof: @@ -188,7 +188,7 @@ def names(root=None): "Get names of defined fonts (as a tuple)" - if not root: + if root is None: root = tkinter._default_root return root.tk.splitlist(root.tk.call("font", "names")) diff -r 3c830691f598 Lib/tkinter/simpledialog.py --- a/Lib/tkinter/simpledialog.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/simpledialog.py Sun Dec 23 20:52:21 2012 +0200 @@ -150,7 +150,7 @@ self.buttonbox() - if not self.initial_focus: + if self.initial_focus is None: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) @@ -259,7 +259,7 @@ minvalue = None, maxvalue = None, parent = None): - if not parent: + if parent is None: parent = tkinter._default_root self.prompt = prompt diff -r 3c830691f598 Lib/tkinter/tix.py --- a/Lib/tkinter/tix.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/tix.py Sun Dec 23 20:52:21 2012 +0200 @@ -397,9 +397,9 @@ 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 = tkinter._default_root - if not master: + if master is None: raise RuntimeError('Too early to create image') if kw and cnf: cnf = _cnfmerge((cnf, kw)) elif kw: cnf = kw @@ -488,9 +488,14 @@ def __init__(self, itemtype, cnf={}, **kw): master = _default_root # global from Tkinter - if not master and 'refwindow' in cnf: master=cnf['refwindow'] - elif not master and 'refwindow' in kw: master= kw['refwindow'] - elif not master: raise RuntimeError("Too early to create display style: no root window") + if master is None: + if 'refwindow' in cnf: + master=cnf['refwindow'] + elif 'refwindow' in kw: + master= kw['refwindow'] + else: + raise RuntimeError("Too early to create display style: " + "no root window") self.tk = master.tk self.stylename = self.tk.call('tixDisplayStyle', itemtype, *self._options(cnf,kw) ) @@ -881,7 +886,7 @@ 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)) diff -r 3c830691f598 Lib/tkinter/ttk.py --- a/Lib/tkinter/ttk.py Sun Dec 23 09:13:33 2012 -0800 +++ b/Lib/tkinter/ttk.py Sun Dec 23 20:52:21 2012 +0200 @@ -358,7 +358,10 @@ RuntimeError is raised.""" if master is None: if tkinter._support_default_root: - master = tkinter._default_root or tkinter.Tk() + if tkinter._default_root is not None: + master = tkinter._default_root + else: + master = tkinter.Tk() else: raise RuntimeError( "No master specified and tkinter is " @@ -576,7 +579,7 @@ then it will be invoked with *args, **kw if the widget state matches statespec. statespec is expected to be a sequence.""" ret = self.tk.call(self._w, "instate", ' '.join(statespec)) - if ret and callback: + if ret and callback is not None: return callback(*args, **kw) return bool(ret)