Commit 41f72aa7 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent fe630b9d
...@@ -2,30 +2,15 @@ ...@@ -2,30 +2,15 @@
__version__ = "$Revision$" __version__ = "$Revision$"
try: import _tkinter # If this fails your Python is not configured for Tk
# See if modern _tkinter is present tkinter = _tkinter # b/w compat for export
import _tkinter TclError = _tkinter.TclError
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
from types import * from types import *
from Tkconstants import * from Tkconstants import *
import string; _string = string; del string import string; _string = string; del string
TkVersion = _string.atof(tkinter.TK_VERSION) TkVersion = _string.atof(_tkinter.TK_VERSION)
TclVersion = _string.atof(tkinter.TCL_VERSION) TclVersion = _string.atof(_tkinter.TCL_VERSION)
###################################################################### ######################################################################
# Since the values of file event masks changed from Tk 4.0 to Tk 4.1, # Since the values of file event masks changed from Tk 4.0 to Tk 4.1,
...@@ -667,7 +652,7 @@ class Tk(Misc, Wm): ...@@ -667,7 +652,7 @@ class Tk(Misc, Wm):
baseName = os.path.basename(sys.argv[0]) baseName = os.path.basename(sys.argv[0])
baseName, ext = os.path.splitext(baseName) baseName, ext = os.path.splitext(baseName)
if ext not in ('.py', 'pyc'): baseName = baseName + ext if ext not in ('.py', 'pyc'): baseName = baseName + ext
self.tk = tkinter.create(screenName, baseName, className) self.tk = _tkinter.create(screenName, baseName, className)
try: try:
# Disable event scanning except for Command-Period # Disable event scanning except for Command-Period
import MacOS import MacOS
...@@ -679,15 +664,15 @@ class Tk(Misc, Wm): ...@@ -679,15 +664,15 @@ class Tk(Misc, Wm):
self.update() self.update()
# Version sanity checks # Version sanity checks
tk_version = self.tk.getvar('tk_version') tk_version = self.tk.getvar('tk_version')
if tk_version != tkinter.TK_VERSION: if tk_version != _tkinter.TK_VERSION:
raise RuntimeError, \ raise RuntimeError, \
"tk.h version (%s) doesn't match libtk.a version (%s)" \ "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') tcl_version = self.tk.getvar('tcl_version')
if tcl_version != tkinter.TCL_VERSION: if tcl_version != _tkinter.TCL_VERSION:
raise RuntimeError, \ raise RuntimeError, \
"tcl.h version (%s) doesn't match libtcl.a version (%s)" \ "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: if TkVersion < 4.0:
raise RuntimeError, \ raise RuntimeError, \
"Tk 4.0 or higher is required; found Tk %s" \ "Tk 4.0 or higher is required; found Tk %s" \
......
...@@ -2,30 +2,15 @@ ...@@ -2,30 +2,15 @@
__version__ = "$Revision$" __version__ = "$Revision$"
try: import _tkinter # If this fails your Python is not configured for Tk
# See if modern _tkinter is present tkinter = _tkinter # b/w compat for export
import _tkinter TclError = _tkinter.TclError
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
from types import * from types import *
from Tkconstants import * from Tkconstants import *
import string; _string = string; del string import string; _string = string; del string
TkVersion = _string.atof(tkinter.TK_VERSION) TkVersion = _string.atof(_tkinter.TK_VERSION)
TclVersion = _string.atof(tkinter.TCL_VERSION) TclVersion = _string.atof(_tkinter.TCL_VERSION)
###################################################################### ######################################################################
# Since the values of file event masks changed from Tk 4.0 to Tk 4.1, # Since the values of file event masks changed from Tk 4.0 to Tk 4.1,
...@@ -667,7 +652,7 @@ class Tk(Misc, Wm): ...@@ -667,7 +652,7 @@ class Tk(Misc, Wm):
baseName = os.path.basename(sys.argv[0]) baseName = os.path.basename(sys.argv[0])
baseName, ext = os.path.splitext(baseName) baseName, ext = os.path.splitext(baseName)
if ext not in ('.py', 'pyc'): baseName = baseName + ext if ext not in ('.py', 'pyc'): baseName = baseName + ext
self.tk = tkinter.create(screenName, baseName, className) self.tk = _tkinter.create(screenName, baseName, className)
try: try:
# Disable event scanning except for Command-Period # Disable event scanning except for Command-Period
import MacOS import MacOS
...@@ -679,15 +664,15 @@ class Tk(Misc, Wm): ...@@ -679,15 +664,15 @@ class Tk(Misc, Wm):
self.update() self.update()
# Version sanity checks # Version sanity checks
tk_version = self.tk.getvar('tk_version') tk_version = self.tk.getvar('tk_version')
if tk_version != tkinter.TK_VERSION: if tk_version != _tkinter.TK_VERSION:
raise RuntimeError, \ raise RuntimeError, \
"tk.h version (%s) doesn't match libtk.a version (%s)" \ "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') tcl_version = self.tk.getvar('tcl_version')
if tcl_version != tkinter.TCL_VERSION: if tcl_version != _tkinter.TCL_VERSION:
raise RuntimeError, \ raise RuntimeError, \
"tcl.h version (%s) doesn't match libtcl.a version (%s)" \ "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: if TkVersion < 4.0:
raise RuntimeError, \ raise RuntimeError, \
"Tk 4.0 or higher is required; found Tk %s" \ "Tk 4.0 or higher is required; found Tk %s" \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment