From: Garvit Khatri Date: Mon, 26 Mar 2018 07:02:05 +0000 (+0530) Subject: bpo-33096: Fix ttk.Treeview.insert. (GH-6228) X-Git-Tag: v3.8.0a1~2038 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ab44c0783eebdff687014f7d14d5dec59b6bd39;p=python bpo-33096: Fix ttk.Treeview.insert. (GH-6228) Allow ttk.Treeview.insert to insert iid that has a false boolean value. Note iid=0 and iid=False would be same. --- diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py index bbc508d358..5b0e29cdcc 100644 --- a/Lib/tkinter/test/test_ttk/test_widgets.py +++ b/Lib/tkinter/test/test_ttk/test_widgets.py @@ -1662,6 +1662,15 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): self.tv.insert('', 'end', text=value), text=None), value) + # test for values which are not None + itemid = self.tv.insert('', 'end', 0) + self.assertEqual(itemid, '0') + itemid = self.tv.insert('', 'end', 0.0) + self.assertEqual(itemid, '0.0') + # this is because False resolves to 0 and element with 0 iid is already present + self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', False) + self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', '') + def test_selection(self): self.assertRaises(TypeError, self.tv.selection, 'spam') diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py index 490b502a65..573544dd84 100644 --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -1361,7 +1361,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): already exist in the tree. Otherwise, a new unique identifier is generated.""" opts = _format_optdict(kw) - if iid: + if iid is not None: res = self.tk.call(self._w, "insert", parent, index, "-id", iid, *opts) else: diff --git a/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst b/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst new file mode 100644 index 0000000000..c55ea20b33 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst @@ -0,0 +1,4 @@ +Allow ttk.Treeview.insert to insert iid that has a false boolean value. +Note iid=0 and iid=False would be same. +Patch by Garvit Khatri. +