[Python-checkins] bpo-41730: Show deprecation warnings for tkinter.tix (GH-22186)

miss-islington webhook-mailer at python.org
Fri May 7 12:14:56 EDT 2021


https://github.com/python/cpython/commit/ec6a1ea1ee67a5e7c8ee5f5b1541bc1c6e17a373
commit: ec6a1ea1ee67a5e7c8ee5f5b1541bc1c6e17a373
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-05-07T09:14:48-07:00
summary:

bpo-41730: Show deprecation warnings for tkinter.tix (GH-22186)


Co-authored-by: E-Paine <63801254+E-Paine at users.noreply.github.com>
Co-authored-by: Zachary Ware <zach at python.org>
(cherry picked from commit 4a2d98a1e98de25c5114d11fcb0f9fedbb057e51)

Co-authored-by: wyz23x2 <52805709+wyz23x2 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2020-09-10-07-23-24.bpo-41730.DyKFi9.rst
M Lib/test/test_tix.py
M Lib/tkinter/tix.py

diff --git a/Lib/test/test_tix.py b/Lib/test/test_tix.py
index e6d759e7bd3b61..a2fb357fd0c500 100644
--- a/Lib/test/test_tix.py
+++ b/Lib/test/test_tix.py
@@ -1,7 +1,7 @@
+import sys
 import unittest
 from test import support
 from test.support import import_helper
-import sys
 
 # Skip this test if the _tkinter module wasn't built.
 _tkinter = import_helper.import_module('_tkinter')
@@ -9,7 +9,9 @@
 # Skip test if tk cannot be initialized.
 support.requires('gui')
 
-from tkinter import tix, TclError
+# Suppress the deprecation warning
+tix = import_helper.import_module('tkinter.tix', deprecated=True)
+from tkinter import TclError
 
 
 class TestTix(unittest.TestCase):
@@ -24,9 +26,12 @@ def setUp(self):
         else:
             self.addCleanup(self.root.destroy)
 
-    def test_tix_available(self):
-        # this test is just here to make setUp run
-        pass
+    def test_tix_deprecation(self):
+        with self.assertWarns(DeprecationWarning):
+            import_helper.import_fresh_module(
+                'tkinter.tix',
+                fresh=('tkinter.tix',),
+                )
 
 
 if __name__ == '__main__':
diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py
index 7d24075403649c..44ecae1a326831 100644
--- a/Lib/tkinter/tix.py
+++ b/Lib/tkinter/tix.py
@@ -21,13 +21,20 @@
 # Compare the demo tixwidgets.py to the original Tcl program and you will
 # appreciate the advantages.
 #
+# NOTE: This module is deprecated since Python 3.6.
 
 import os
+import warnings
 import tkinter
 from tkinter import *
 from tkinter import _cnfmerge
 
-import _tkinter # If this fails your Python may not be configured for Tk
+warnings.warn(
+    'The Tix Tk extension is unmaintained, and the tkinter.tix wrapper module'
+    ' is deprecated in favor of tkinter.ttk',
+    DeprecationWarning,
+    stacklevel=2,
+    )
 
 # Some more constants (for consistency with Tkinter)
 WINDOW = 'window'
diff --git a/Misc/NEWS.d/next/Library/2020-09-10-07-23-24.bpo-41730.DyKFi9.rst b/Misc/NEWS.d/next/Library/2020-09-10-07-23-24.bpo-41730.DyKFi9.rst
new file mode 100644
index 00000000000000..63d8353a7aab2e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-09-10-07-23-24.bpo-41730.DyKFi9.rst
@@ -0,0 +1 @@
+``DeprecationWarning`` is now raised when importing :mod:`tkinter.tix`, which has been deprecated in documentation since Python 3.6.



More information about the Python-checkins mailing list