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
10 changes: 5 additions & 5 deletions Doc/library/tkinter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ Base and mixin classes

.. method:: winfo_exists()

Return ``1`` if the widget exists, ``0`` otherwise.
Return ``True`` if the widget exists, ``False`` otherwise.

.. method:: winfo_fpixels(number)

Expand Down Expand Up @@ -2115,7 +2115,7 @@ Base and mixin classes

.. method:: winfo_ismapped()

Return ``1`` if the widget is currently mapped, ``0`` otherwise.
Return ``True`` if the widget is currently mapped, ``False`` otherwise.

.. method:: winfo_manager()

Expand Down Expand Up @@ -2246,8 +2246,8 @@ Base and mixin classes

.. method:: winfo_viewable()

Return ``1`` if the widget and all of its ancestors up through the
nearest toplevel window are mapped, ``0`` otherwise.
Return ``True`` if the widget and all of its ancestors up through the
nearest toplevel window are mapped, ``False`` otherwise.

.. method:: winfo_visual()

Expand Down Expand Up @@ -5737,7 +5737,7 @@ Widget classes
.. method:: edit_modified(arg=None)

If *arg* is omitted, return the current state of the modified flag as
``0`` or ``1``; the flag is set automatically whenever the text is
a :class:`bool`; the flag is set automatically whenever the text is
inserted or deleted.
Otherwise set the flag to the boolean *arg*.

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/tkinter.ttk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ ttk.Treeview
Without arguments, returns a tuple of all detached items,
but not their descendants (see :meth:`detached_all`).
With *item*, returns whether *item* is detached; since Tk 9.1, also
returns true if an ancestor of *item* is detached.
returns ``True`` if an ancestor of *item* is detached.

Requires Tk 9.0 or newer.

Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_tkinter/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,12 @@ def test_data(self):

def test_transparency(self):
image = self.create()
self.assertEqual(image.transparency_get(0, 0), True)
self.assertEqual(image.transparency_get(4, 6), False)
self.assertIs(image.transparency_get(0, 0), True)
self.assertIs(image.transparency_get(4, 6), False)
image.transparency_set(4, 6, True)
self.assertEqual(image.transparency_get(4, 6), True)
self.assertIs(image.transparency_get(4, 6), True)
image.transparency_set(4, 6, False)
self.assertEqual(image.transparency_get(4, 6), False)
self.assertIs(image.transparency_get(4, 6), False)
self.assertRaises(tkinter.TclError, image.transparency_get, -1, 0)
self.assertRaises(tkinter.TclError, image.transparency_get, 16, 0)
self.assertRaises(tkinter.TclError, image.transparency_set, -1, 0, True)
Expand Down
17 changes: 15 additions & 2 deletions Lib/test/test_tkinter/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,26 @@ def test_winfo_visual_info(self):
self.assertIsInstance(name, str)
self.assertIsInstance(depth, int)

def test_winfo_exists(self):
f = tkinter.Frame(self.root)
self.assertIs(f.winfo_exists(), True)
f.destroy()
self.assertIs(f.winfo_exists(), False)

def test_winfo_ismapped(self):
f = tkinter.Frame(self.root)
self.assertIs(f.winfo_ismapped(), False)
f.pack()
self.root.update()
self.assertIs(f.winfo_ismapped(), True)

def test_winfo_viewable(self):
f = tkinter.Frame(self.root)
self.assertFalse(f.winfo_viewable())
self.assertIs(f.winfo_viewable(), False)
f.pack()
f.wait_visibility()
self.root.update()
self.assertTrue(f.winfo_viewable())
self.assertIs(f.winfo_viewable(), True)

@requires_tk(9, 1)
def test_winfo_isdark(self):
Expand Down
16 changes: 8 additions & 8 deletions Lib/test/test_tkinter/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def test_debug(self):
text = self.text
olddebug = text.debug()
try:
text.debug(0)
self.assertEqual(text.debug(), 0)
text.debug(1)
self.assertEqual(text.debug(), 1)
text.debug(False)
self.assertIs(text.debug(), False)
text.debug(True)
self.assertIs(text.debug(), True)
finally:
text.debug(olddebug)
self.assertEqual(text.debug(), olddebug)
Expand Down Expand Up @@ -293,13 +293,13 @@ def test_tag_cget_configure(self):

def test_edit_modified(self):
text = self.text
self.assertEqual(text.edit_modified(), 0)
self.assertIs(text.edit_modified(), False)
text.insert('1.0', 'spam')
self.assertEqual(text.edit_modified(), 1)
self.assertIs(text.edit_modified(), True)
text.edit_modified(False)
self.assertEqual(text.edit_modified(), 0)
self.assertIs(text.edit_modified(), False)
text.edit_modified(True)
self.assertEqual(text.edit_modified(), 1)
self.assertIs(text.edit_modified(), True)

def test_edit_undo_redo(self):
text = self.text
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1685,9 +1685,9 @@ def test_detach_reattach(self):
self.assertEqual(self.tv.get_children(item_id), ())

def test_exists(self):
self.assertEqual(self.tv.exists('something'), False)
self.assertEqual(self.tv.exists(''), True)
self.assertEqual(self.tv.exists({}), False)
self.assertIs(self.tv.exists('something'), False)
self.assertIs(self.tv.exists(''), True)
self.assertIs(self.tv.exists({}), False)

# the following will make a tk.call equivalent to
# tk.call(treeview, "exists") which should result in an error
Expand Down
14 changes: 8 additions & 6 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,8 @@ def winfo_depth(self):
return self.tk.getint(self.tk.call('winfo', 'depth', self._w))

def winfo_exists(self):
"""Return true if this widget exists."""
return self.tk.getint(
"""Return True if this widget exists."""
return self.tk.getboolean(
self.tk.call('winfo', 'exists', self._w))

def winfo_fpixels(self, number):
Expand Down Expand Up @@ -1370,8 +1370,8 @@ def winfo_isdark(self): # new in Tk 9.1
self.tk.call('winfo', 'isdark', self._w))

def winfo_ismapped(self):
"""Return true if this widget is mapped."""
return self.tk.getint(
"""Return True if this widget is mapped."""
return self.tk.getboolean(
self.tk.call('winfo', 'ismapped', self._w))

def winfo_manager(self):
Expand Down Expand Up @@ -1498,8 +1498,8 @@ def winfo_toplevel(self):
'winfo', 'toplevel', self._w))

def winfo_viewable(self):
"""Return true if the widget and all its higher ancestors are mapped."""
return self.tk.getint(
"""Return True if the widget and all its higher ancestors are mapped."""
return self.tk.getboolean(
self.tk.call('winfo', 'viewable', self._w))

def winfo_visual(self):
Expand Down Expand Up @@ -4207,6 +4207,8 @@ def edit_modified(self, arg=None):
modified flag. If boolean is specified, sets the
modified flag of the widget to arg.
"""
if arg is None:
return self.tk.getboolean(self.edit("modified"))
return self.edit("modified", arg)

def edit_redo(self):
Expand Down
6 changes: 3 additions & 3 deletions Lib/tkinter/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ def detached(self, item=None):

Without arguments, return a tuple of all detached items (but not
their descendants; see detached_all). With item, return whether item
is detached; since Tk 9.1, also return true if an ancestor of item
is detached; since Tk 9.1, also return True if an ancestor of item
is detached.

* Availability: Tk 9.0"""
Expand Down Expand Up @@ -2031,8 +2031,8 @@ def tag_configure(self, tagname, option=None, **kw):


def tag_has(self, tagname, item=None):
"""If item is specified, returns 1 or 0 depending on whether the
specified item has the given tagname. Otherwise, returns a list of
"""If item is specified, returns True if the specified item has the
given tagname, False otherwise. Otherwise, returns a list of
all items which have the specified tag.

* Availability: Tk 8.6"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:meth:`!winfo_exists`, :meth:`!winfo_ismapped` and :meth:`!winfo_viewable`
methods of :mod:`tkinter` widgets and :meth:`!edit_modified` of
:class:`tkinter.Text` now return a :class:`bool` instead of an integer or,
depending on ``wantobjects``, a string.
Loading