Toplevel widget of Tk which represents mostly the main window of an application. It has an associated Tcl interpreter.
| 2318 | |
| 2319 | |
| 2320 | class Tk(Misc, Wm): |
| 2321 | """Toplevel widget of Tk which represents mostly the main window |
| 2322 | of an application. It has an associated Tcl interpreter.""" |
| 2323 | _w = '.' |
| 2324 | |
| 2325 | def __init__(self, screenName=None, baseName=None, className='Tk', |
| 2326 | useTk=True, sync=False, use=None): |
| 2327 | """Return a new top level widget on screen SCREENNAME. A new Tcl interpreter will |
| 2328 | be created. BASENAME will be used for the identification of the profile file (see |
| 2329 | readprofile). |
| 2330 | It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME |
| 2331 | is the name of the widget class.""" |
| 2332 | self.master = None |
| 2333 | self.children = {} |
| 2334 | self._tkloaded = False |
| 2335 | # to avoid recursions in the getattr code in case of failure, we |
| 2336 | # ensure that self.tk is always _something_. |
| 2337 | self.tk = None |
| 2338 | if baseName is None: |
| 2339 | import os |
| 2340 | baseName = os.path.basename(sys.argv[0]) |
| 2341 | baseName, ext = os.path.splitext(baseName) |
| 2342 | if ext not in ('.py', '.pyc'): |
| 2343 | baseName = baseName + ext |
| 2344 | interactive = False |
| 2345 | self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) |
| 2346 | if useTk: |
| 2347 | self._loadtk() |
| 2348 | if not sys.flags.ignore_environment: |
| 2349 | # Issue #16248: Honor the -E flag to avoid code injection. |
| 2350 | self.readprofile(baseName, className) |
| 2351 | |
| 2352 | def loadtk(self): |
| 2353 | if not self._tkloaded: |
| 2354 | self.tk.loadtk() |
| 2355 | self._loadtk() |
| 2356 | |
| 2357 | def _loadtk(self): |
| 2358 | self._tkloaded = True |
| 2359 | global _default_root |
| 2360 | # Version sanity checks |
| 2361 | tk_version = self.tk.getvar('tk_version') |
| 2362 | if tk_version != _tkinter.TK_VERSION: |
| 2363 | raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)" |
| 2364 | % (_tkinter.TK_VERSION, tk_version)) |
| 2365 | # Under unknown circumstances, tcl_version gets coerced to float |
| 2366 | tcl_version = str(self.tk.getvar('tcl_version')) |
| 2367 | if tcl_version != _tkinter.TCL_VERSION: |
| 2368 | raise RuntimeError("tcl.h version (%s) doesn't match libtcl.a version (%s)" \ |
| 2369 | % (_tkinter.TCL_VERSION, tcl_version)) |
| 2370 | # Create and register the tkerror and exit commands |
| 2371 | # We need to inline parts of _register here, _ register |
| 2372 | # would register differently-named commands. |
| 2373 | if self._tclCommands is None: |
| 2374 | self._tclCommands = [] |
| 2375 | self.tk.createcommand('tkerror', _tkerror) |
| 2376 | self.tk.createcommand('exit', _exit) |
| 2377 | self._tclCommands.append('tkerror') |
no outgoing calls
no test coverage detected