From 3ab44c0783eebdff687014f7d14d5dec59b6bd39 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 26 Mar 2018 12:32:05 +0530 Subject: 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. --- Lib/tkinter/test/test_ttk/test_widgets.py | 9 +++++++++ Lib/tkinter/ttk.py | 2 +- .../NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py index bbc508d..5b0e29c 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 490b502..573544d 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 0000000..c55ea20 --- /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. + -- cgit v0.12