Tkinter对话框
你好我的脚本在python中运行良好,但在我的程序中运行不好(SDS/2 wich是一个类似Autocad的软件).问题是,当读取第14行到第19行时,我遇到了一个错误.(源代码来自Tkinter.py)
选择 | 换行 | 行号
- class Tk(Misc, Wm):
- """Toplevel widget of Tk which represents mostly the main window
- of an appliation. It has an associated Tcl interpreter."""
- _w = '.'
- def __init__(self, screenName=None, baseName=None, className='Tk'):
- """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
- be created. BASENAME will be used for the identification of the profile file (see
- readprofile).
- It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
- is the name of the widget class."""
- global _default_root
- self.master = None
- self.children = {}
- if baseName is None:
- import sys, os
- baseName = os.path.basename(sys.argv[0])
- baseName, ext = os.path.splitext(baseName)
- if ext not in ('.py', '.pyc', '.pyo'):
- baseName = baseName + ext
- self.tk = _tkinter.create(screenName, baseName, className)
- self.tk.wantobjects(wantobjects)
- if _MacOS and hasattr(_MacOS, 'SchedParams'):
- # Disable event scanning except for Command-Period
- _MacOS.SchedParams(1, 0)
- # Work around nasty MacTk bug
- # XXX Is this one still needed?
- self.update()
- # Version sanity checks
- tk_version = self.tk.getvar('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)
- # Under unknown circumstances, tcl_version gets coerced to float
- tcl_version = str(self.tk.getvar('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)
- if TkVersion < 4.0:
- raise RuntimeError, \
- "Tk 4.0 or higher is required; found Tk %s" \
- % str(TkVersion)
- self.tk.createcommand('tkerror', _tkerror)
- self.tk.createcommand('exit', _exit)
- self.readprofile(baseName, className)
- if _support_default_root and not _default_root:
- _default_root = self
- self.protocol("WM_DELETE_WINDOW", self.destroy)
- def destroy(self):
- """Destroy this and all descendants widgets. This will
- end the application of this Tcl interpreter."""
- for c in self.children.values(): c.destroy()
- self.tk.call('destroy', self._w)
- Misc.destroy(self)
- global _default_root
- if _support_default_root and _default_root is self:
- _default_root = None
- def readprofile(self, baseName, className):
- """Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
- the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if
- such a file exists in the home directory."""
- 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):
- self.tk.call('source', class_tcl)
- if os.path.isfile(class_py):
- execfile(class_py, dir)
- if os.path.isfile(base_tcl):
- self.tk.call('source', base_tcl)
- if os.path.isfile(base_py):
- execfile(base_py, dir)
- def report_callback_exception(self, exc, val, tb):
- """Internal function. It reports exception on sys.stderr."""
- import traceback, sys
- sys.stderr.write("Exception in Tkinter callback\n")
- sys.last_type = exc
- sys.last_value = val
- sys.last_traceback = tb
- traceback.print_exception(exc, val, tb)
因此,我希望能够在这些代码行中提供baseName变量,以覆盖下面的14到19行.
选择 | 换行 | 行号
- Tkinter(baseName = file_name_path).Label(text=" ").pack()
- Tkinter(baseName = file_name_path).Label(text="TEST Dialog Box").pack()
- Tkinter(baseName = file_name_path).Label(text=" ").pack()
- mainloop()
有可能这样做吗?非常感谢.