Kaydet (Commit) 10d0f8fc authored tarafından Jack Jansen's avatar Jack Jansen

Renamed module tkinter to _tkinter

üst f39ca24e
Several collections of example code for Tkinter. Several collections of example code for Tkinter.
See the toplevel README for an explanation of the difference between See the toplevel README for an explanation of the difference between
Tkinter and tkinter, how to enable the Python Tk interface, and where Tkinter and _tkinter, how to enable the Python Tk interface, and where
to get Matt Conway's lifesaver document. to get Matt Conway's lifesaver document.
Subdirectories: Subdirectories:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import regex import regex
from Tkinter import * from Tkinter import *
from Tkinter import _tkinter
from ScrolledText import ScrolledText from ScrolledText import ScrolledText
# XXX These fonts may have to be changed to match your system # XXX These fonts may have to be changed to match your system
...@@ -44,7 +45,7 @@ class EditableManPage(ScrolledText): ...@@ -44,7 +45,7 @@ class EditableManPage(ScrolledText):
# Parse a file, in the background # Parse a file, in the background
def asyncparsefile(self, fp): def asyncparsefile(self, fp):
self._startparser(fp) self._startparser(fp)
self.tk.createfilehandler(fp, tkinter.READABLE, self.tk.createfilehandler(fp, _tkinter.READABLE,
self._filehandler) self._filehandler)
parsefile = asyncparsefile # Alias parsefile = asyncparsefile # Alias
......
# This is about all it requires to write a wish shell in Python! # This is about all it requires to write a wish shell in Python!
import tkinter import _tkinter
import os import os
tk = tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1) tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1)
tk.call('update') tk.call('update')
cmd = '' cmd = ''
...@@ -20,7 +20,7 @@ while 1: ...@@ -20,7 +20,7 @@ while 1:
tk.record(line) tk.record(line)
try: try:
result = tk.call('eval', cmd) result = tk.call('eval', cmd)
except tkinter.TclError, msg: except _tkinter.TclError, msg:
print 'TclError:', msg print 'TclError:', msg
else: else:
if result: print result if result: print result
......
# Tkinter.py -- Tk/Tcl widget wrappers # Tkinter.py -- Tk/Tcl widget wrappers
import tkinter import _tkinter
from tkinter import TclError from _tkinter import TclError
from types import * from types import *
from Tkconstants import * from Tkconstants import *
CallableTypes = (FunctionType, MethodType, CallableTypes = (FunctionType, MethodType,
BuiltinFunctionType, BuiltinMethodType) BuiltinFunctionType, BuiltinMethodType)
TkVersion = eval(tkinter.TK_VERSION) TkVersion = eval(_tkinter.TK_VERSION)
TclVersion = eval(tkinter.TCL_VERSION) TclVersion = eval(_tkinter.TCL_VERSION)
def _flatten(tuple): def _flatten(tuple):
...@@ -575,18 +575,18 @@ class Tk(Misc, Wm): ...@@ -575,18 +575,18 @@ class Tk(Misc, Wm):
import sys, os import sys, os
baseName = os.path.basename(sys.argv[0]) baseName = os.path.basename(sys.argv[0])
if baseName[-3:] == '.py': baseName = baseName[:-3] if baseName[-3:] == '.py': baseName = baseName[:-3]
self.tk = tkinter.create(screenName, baseName, className) self.tk = _tkinter.create(screenName, baseName, className)
# 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" \
......
# Tkinter.py -- Tk/Tcl widget wrappers # Tkinter.py -- Tk/Tcl widget wrappers
import tkinter import _tkinter
from tkinter import TclError from _tkinter import TclError
from types import * from types import *
from Tkconstants import * from Tkconstants import *
CallableTypes = (FunctionType, MethodType, CallableTypes = (FunctionType, MethodType,
BuiltinFunctionType, BuiltinMethodType) BuiltinFunctionType, BuiltinMethodType)
TkVersion = eval(tkinter.TK_VERSION) TkVersion = eval(_tkinter.TK_VERSION)
TclVersion = eval(tkinter.TCL_VERSION) TclVersion = eval(_tkinter.TCL_VERSION)
def _flatten(tuple): def _flatten(tuple):
...@@ -575,18 +575,18 @@ class Tk(Misc, Wm): ...@@ -575,18 +575,18 @@ class Tk(Misc, Wm):
import sys, os import sys, os
baseName = os.path.basename(sys.argv[0]) baseName = os.path.basename(sys.argv[0])
if baseName[-3:] == '.py': baseName = baseName[:-3] if baseName[-3:] == '.py': baseName = baseName[:-3]
self.tk = tkinter.create(screenName, baseName, className) self.tk = _tkinter.create(screenName, baseName, className)
# 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" \
......
...@@ -113,7 +113,7 @@ Here's an overview of the questions per chapter: ...@@ -113,7 +113,7 @@ Here's an overview of the questions per chapter:
3.14. Q. Under Solaris 2.x, using GCC, how do I use shared libraries? 3.14. Q. Under Solaris 2.x, using GCC, how do I use shared libraries?
3.15. Q. Errors when linking with a shared library containing C++ code. 3.15. Q. Errors when linking with a shared library containing C++ code.
3.16. Q. Tk menus or radiobuttons don't work properly in Python 1.2. 3.16. Q. Tk menus or radiobuttons don't work properly in Python 1.2.
3.17. Q. I built with tkintermodule.c enabled but get "Tkinter not found". 3.17. Q. I built with _tkintermodule.c enabled but get "Tkinter not found".
3.18. Q. I built with Tk 4.0 but Tkinter complains about the Tk version. 3.18. Q. I built with Tk 4.0 but Tkinter complains about the Tk version.
3.19. Q. Tk doesn't work right on DEC Alpha. 3.19. Q. Tk doesn't work right on DEC Alpha.
...@@ -876,7 +876,7 @@ edit config.c slightly to make it compilable with C++. ...@@ -876,7 +876,7 @@ edit config.c slightly to make it compilable with C++.
A. There's a bug in Tkinter.py; remove ClassType and InstanceType from A. There's a bug in Tkinter.py; remove ClassType and InstanceType from
the definition of CallableTypes near the top of Lib/tkinter/Tkinter.py. the definition of CallableTypes near the top of Lib/tkinter/Tkinter.py.
3.17. Q. I built with tkintermodule.c enabled but get "Tkinter not found". 3.17. Q. I built with _tkintermodule.c enabled but get "Tkinter not found".
A. Tkinter.py (note: upper case T) lives in a subdirectory of Lib, A. Tkinter.py (note: upper case T) lives in a subdirectory of Lib,
Lib/tkinter. If you are using the default module search path, you Lib/tkinter. If you are using the default module search path, you
...@@ -1111,10 +1111,10 @@ the module only works on specific platforms (e.g. gl only works on SGI ...@@ -1111,10 +1111,10 @@ the module only works on specific platforms (e.g. gl only works on SGI
machines). machines).
NOTE: if the complaint is about "Tkinter" (upper case T) and you have NOTE: if the complaint is about "Tkinter" (upper case T) and you have
already configured module "tkinter" (lower case t), the solution is already configured module "_tkinter" (lower case t and underscore),
*not* to rename tkinter to Tkinter or vice versa. There is probably the solution is *not* to rename tkinter to Tkinter or vice versa.
something wrong with your module search path. Check out the value of There is probably something wrong with your module search path. Check
sys.path. out the value of sys.path.
For X-related modules (Xt and Xm) you will have to do more work: they For X-related modules (Xt and Xm) you will have to do more work: they
are currently not part of the standard Python distribution. You will are currently not part of the standard Python distribution. You will
......
...@@ -450,8 +450,8 @@ found in Lib/tk3inter/.) ...@@ -450,8 +450,8 @@ found in Lib/tk3inter/.)
To enable the Python/Tk interface, once you've built and installed To enable the Python/Tk interface, once you've built and installed
Tcl/Tk, all you need to do is edit two lines in Modules/Setup; search Tcl/Tk, all you need to do is edit two lines in Modules/Setup; search
for the string "tkinter". Un-comment one (normally the first) of the for the string "_tkinter". Un-comment one (normally the first) of the
lines beginning with "#tkinter" and un-comment the line beginning with lines beginning with "#_tkinter" and un-comment the line beginning with
"#TKPATH". (If you have installed Tcl/Tk in unusual places you will "#TKPATH". (If you have installed Tcl/Tk in unusual places you will
have to edit the first line as well to fix the -I and -L options.) have to edit the first line as well to fix the -I and -L options.)
See the Build Instructions above for more details. See the Build Instructions above for more details.
...@@ -463,15 +463,15 @@ the Demo/tkinter directory, in the subdirectories guido, matt and www. ...@@ -463,15 +463,15 @@ the Demo/tkinter directory, in the subdirectories guido, matt and www.
Note that there's a Python module called "Tkinter" (capital T) which Note that there's a Python module called "Tkinter" (capital T) which
lives in Lib/tkinter/Tkinter.py, and a C module called "tkinter" lives in Lib/tkinter/Tkinter.py, and a C module called "tkinter"
(lower case t) which lives in Modules/tkintermodule.c. Demos and (lower case t) which lives in Modules/_tkinter.c. Demos and
normal Tk applications only import the Python Tkinter module -- only normal Tk applications only import the Python Tkinter module -- only
the latter uses the C tkinter module directly. In order to find the C the latter uses the C _tkinter module directly. In order to find the C
tkinter module, it must be compiled and linked into the Python _tkinter module, it must be compiled and linked into the Python
interpreter -- the tkinter line in the Setup file does this. In order interpreter -- the _tkinter line in the Setup file does this. In order
to find the Python Tkinter module, sys.path must be set correctly -- to find the Python Tkinter module, sys.path must be set correctly --
the TKPATH assignment in the Setup file takes care of this, but only the TKPATH assignment in the Setup file takes care of this, but only
if you install Python properly ("make install libinstall"). (You can if you install Python properly ("make install libinstall"). (You can
also use dynamic loading for the C tkinter module, in which case you also use dynamic loading for the C _tkinter module, in which case you
must manually fix up sys.path or set $PYTHONPATH for the Python must manually fix up sys.path or set $PYTHONPATH for the Python
Tkinter module.) Tkinter module.)
......
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