.. method:: winfo_exists()
- Return ``1`` if the widget exists, ``0`` otherwise.
+ Return ``True`` if the widget exists, ``False`` otherwise.
.. method:: winfo_fpixels(number)
.. 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()
.. 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()
.. 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*.
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.
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)
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):
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)
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
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
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):
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):
'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):
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):
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"""
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"""
--- /dev/null
+: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.