[PYTHONMAC-SIG] Default Tk attributes?
Guido van Rossum
guido@CNRI.Reston.Va.US
Tue, 31 Dec 1996 10:50:18 -0500
> Having said that, there is still a very small difference in the
> cross-platform behaviours: I guess the file ~/.xdefaults is
> automatically considered by Tk on UNIX (at least that is what Matt's
> book says). On the other hand, there is definitely no automatic
> configuration on the Mac. What it would require is to slightly modify
> the Tkinter file to read in such a file and interpret it in, say, the
> __init__ of the class Misc (or Tk). Is it worth bothering? Maybe not...
There's already a "user profile" option in Tkinter. The Tk class
calls the following method on startup:
def readprofile(self, baseName, className):
import os
if os.environ.has_key('HOME'): home = os.environ['HOME']
else: home = os.curdir
class_tcl = os.path.join(home, '.%s.tcl' % className)
class_py = os.path.join(home, '.%s.py' % className)
base_tcl = os.path.join(home, '.%s.tcl' % baseName)
base_py = os.path.join(home, '.%s.py' % baseName)
dir = {'self': self}
exec 'from Tkinter import *' in dir
if os.path.isfile(class_tcl):
print 'source', `class_tcl`
self.tk.call('source', class_tcl)
if os.path.isfile(class_py):
print 'execfile', `class_py`
execfile(class_py, dir)
if os.path.isfile(base_tcl):
print 'source', `base_tcl`
self.tk.call('source', base_tcl)
if os.path.isfile(base_py):
print 'execfile', `base_py`
execfile(base_py, dir)
It seems that on the Mac this will execute a file ``.<classname>.py''
(note leading dot!) in the current directory, where <classname> is the
class passed to Tk -- it defaults to 'Tk'. It will also read
``.<basename>.py'' where basename is the base component of sys.argv[0]
-- in other words, the script or program name.
--Guido van Rossum (home page: http://www.python.org/~guido/)
=================
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
=================