Skip to content

Commit 4a2d98a

Browse files
wyz23x2E-Painezware
authored
bpo-41730: Show deprecation warnings for tkinter.tix (GH-22186)
Co-authored-by: E-Paine <[email protected]> Co-authored-by: Zachary Ware <[email protected]>
1 parent adcd220 commit 4a2d98a

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Lib/test/test_tix.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import sys
12
import unittest
23
from test import support
34
from test.support import import_helper
4-
import sys
55

66
# Skip this test if the _tkinter module wasn't built.
77
_tkinter = import_helper.import_module('_tkinter')
88

99
# Skip test if tk cannot be initialized.
1010
support.requires('gui')
1111

12-
from tkinter import tix, TclError
12+
# Suppress the deprecation warning
13+
tix = import_helper.import_module('tkinter.tix', deprecated=True)
14+
from tkinter import TclError
1315

1416

1517
class TestTix(unittest.TestCase):
@@ -24,9 +26,12 @@ def setUp(self):
2426
else:
2527
self.addCleanup(self.root.destroy)
2628

27-
def test_tix_available(self):
28-
# this test is just here to make setUp run
29-
pass
29+
def test_tix_deprecation(self):
30+
with self.assertWarns(DeprecationWarning):
31+
import_helper.import_fresh_module(
32+
'tkinter.tix',
33+
fresh=('tkinter.tix',),
34+
)
3035

3136

3237
if __name__ == '__main__':

Lib/tkinter/tix.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@
2121
# Compare the demo tixwidgets.py to the original Tcl program and you will
2222
# appreciate the advantages.
2323
#
24+
# NOTE: This module is deprecated since Python 3.6.
2425

2526
import os
27+
import warnings
2628
import tkinter
2729
from tkinter import *
2830
from tkinter import _cnfmerge
2931

30-
import _tkinter # If this fails your Python may not be configured for Tk
32+
warnings.warn(
33+
'The Tix Tk extension is unmaintained, and the tkinter.tix wrapper module'
34+
' is deprecated in favor of tkinter.ttk',
35+
DeprecationWarning,
36+
stacklevel=2,
37+
)
3138

3239
# Some more constants (for consistency with Tkinter)
3340
WINDOW = 'window'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``DeprecationWarning`` is now raised when importing :mod:`tkinter.tix`, which has been deprecated in documentation since Python 3.6.

0 commit comments

Comments
 (0)