diff options
author | Guido van Rossum <guido@python.org> | 1997-02-15 18:33:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-02-15 18:33:24 (GMT) |
commit | 9580609ba30d86fe33aa8c119644403ed68e428b (patch) | |
tree | b1425ec5ae5077efea56434da6e0aa0a58a3296f /Lib | |
parent | 10efb05d517d9d33416083cf2d9aba1cc93a5ffe (diff) | |
download | cpython-9580609ba30d86fe33aa8c119644403ed68e428b.zip cpython-9580609ba30d86fe33aa8c119644403ed68e428b.tar.gz cpython-9580609ba30d86fe33aa8c119644403ed68e428b.tar.bz2 |
Require _tkinter -- don't attempt to import tkinter when _tkinter does
not exist. All 8 uses of tkinter are replaced with _tkinter. Still
create a variable tkinter though, because that is used by other
modules importing Tkinter (e.g. tkinter.createfilehandler()).
Also added a comment to the 'import _tkinter' line saying that if this
fails, Python is not configured correctly.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/lib-tk/Tkinter.py | 35 | ||||
-rwxr-xr-x | Lib/tkinter/Tkinter.py | 35 |
2 files changed, 20 insertions, 50 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index 5a0cb3d..c492d8d 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -2,30 +2,15 @@ __version__ = "$Revision$" -try: - # See if modern _tkinter is present - import _tkinter - tkinter = _tkinter # b/w compat -except ImportError: - # No modern _tkinter -- try oldfashioned tkinter - import tkinter - if hasattr(tkinter, "__path__"): - import sys, os - # Append standard platform specific directory - p = tkinter.__path__ - for dir in sys.path: - if (dir not in p and - os.path.basename(dir) == sys.platform): - p.append(dir) - del sys, os, p, dir - from tkinter import tkinter -TclError = tkinter.TclError +import _tkinter # If this fails your Python is not configured for Tk +tkinter = _tkinter # b/w compat for export +TclError = _tkinter.TclError from types import * from Tkconstants import * import string; _string = string; del string -TkVersion = _string.atof(tkinter.TK_VERSION) -TclVersion = _string.atof(tkinter.TCL_VERSION) +TkVersion = _string.atof(_tkinter.TK_VERSION) +TclVersion = _string.atof(_tkinter.TCL_VERSION) ###################################################################### # Since the values of file event masks changed from Tk 4.0 to Tk 4.1, @@ -667,7 +652,7 @@ class Tk(Misc, Wm): baseName = os.path.basename(sys.argv[0]) baseName, ext = os.path.splitext(baseName) if ext not in ('.py', 'pyc'): baseName = baseName + ext - self.tk = tkinter.create(screenName, baseName, className) + self.tk = _tkinter.create(screenName, baseName, className) try: # Disable event scanning except for Command-Period import MacOS @@ -679,15 +664,15 @@ class Tk(Misc, Wm): self.update() # Version sanity checks tk_version = self.tk.getvar('tk_version') - if tk_version != tkinter.TK_VERSION: + if tk_version != _tkinter.TK_VERSION: raise RuntimeError, \ "tk.h version (%s) doesn't match libtk.a version (%s)" \ - % (tkinter.TK_VERSION, tk_version) + % (_tkinter.TK_VERSION, tk_version) tcl_version = self.tk.getvar('tcl_version') - if tcl_version != tkinter.TCL_VERSION: + if tcl_version != _tkinter.TCL_VERSION: raise RuntimeError, \ "tcl.h version (%s) doesn't match libtcl.a version (%s)" \ - % (tkinter.TCL_VERSION, tcl_version) + % (_tkinter.TCL_VERSION, tcl_version) if TkVersion < 4.0: raise RuntimeError, \ "Tk 4.0 or higher is required; found Tk %s" \ diff --git a/Lib/tkinter/Tkinter.py b/Lib/tkinter/Tkinter.py index 5a0cb3d..c492d8d 100755 --- a/Lib/tkinter/Tkinter.py +++ b/Lib/tkinter/Tkinter.py @@ -2,30 +2,15 @@ __version__ = "$Revision$" -try: - # See if modern _tkinter is present - import _tkinter - tkinter = _tkinter # b/w compat -except ImportError: - # No modern _tkinter -- try oldfashioned tkinter - import tkinter - if hasattr(tkinter, "__path__"): - import sys, os - # Append standard platform specific directory - p = tkinter.__path__ - for dir in sys.path: - if (dir not in p and - os.path.basename(dir) == sys.platform): - p.append(dir) - del sys, os, p, dir - from tkinter import tkinter -TclError = tkinter.TclError +import _tkinter # If this fails your Python is not configured for Tk +tkinter = _tkinter # b/w compat for export +TclError = _tkinter.TclError from types import * from Tkconstants import * import string; _string = string; del string -TkVersion = _string.atof(tkinter.TK_VERSION) -TclVersion = _string.atof(tkinter.TCL_VERSION) +TkVersion = _string.atof(_tkinter.TK_VERSION) +TclVersion = _string.atof(_tkinter.TCL_VERSION) ###################################################################### # Since the values of file event masks changed from Tk 4.0 to Tk 4.1, @@ -667,7 +652,7 @@ class Tk(Misc, Wm): baseName = os.path.basename(sys.argv[0]) baseName, ext = os.path.splitext(baseName) if ext not in ('.py', 'pyc'): baseName = baseName + ext - self.tk = tkinter.create(screenName, baseName, className) + self.tk = _tkinter.create(screenName, baseName, className) try: # Disable event scanning except for Command-Period import MacOS @@ -679,15 +664,15 @@ class Tk(Misc, Wm): self.update() # Version sanity checks tk_version = self.tk.getvar('tk_version') - if tk_version != tkinter.TK_VERSION: + if tk_version != _tkinter.TK_VERSION: raise RuntimeError, \ "tk.h version (%s) doesn't match libtk.a version (%s)" \ - % (tkinter.TK_VERSION, tk_version) + % (_tkinter.TK_VERSION, tk_version) tcl_version = self.tk.getvar('tcl_version') - if tcl_version != tkinter.TCL_VERSION: + if tcl_version != _tkinter.TCL_VERSION: raise RuntimeError, \ "tcl.h version (%s) doesn't match libtcl.a version (%s)" \ - % (tkinter.TCL_VERSION, tcl_version) + % (_tkinter.TCL_VERSION, tcl_version) if TkVersion < 4.0: raise RuntimeError, \ "Tk 4.0 or higher is required; found Tk %s" \ |