MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/tkinter/__init__.py:386–414  ·  view source on GitHub ↗

Construct a variable MASTER can be given as master widget. VALUE is an optional value (defaults to "") NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.

(self, master=None, value=None, name=None)

Source from the content-addressed store, hash-verified

384 _tclCommands = None
385
386 def __init__(self, master=None, value=None, name=None):
387 """Construct a variable
388
389 MASTER can be given as master widget.
390 VALUE is an optional value (defaults to "")
391 NAME is an optional Tcl name (defaults to PY_VARnum).
392
393 If NAME matches an existing variable and VALUE is omitted
394 then the existing value is retained.
395 """
396 # check for type of NAME parameter to override weird error message
397 # raised from Modules/_tkinter.c:SetVar like:
398 # TypeError: setvar() takes exactly 3 arguments (2 given)
399 if name is not None and not isinstance(name, str):
400 raise TypeError("name must be a string")
401 global _varnum
402 if master is None:
403 master = _get_default_root('create variable')
404 self._root = master._root()
405 self._tk = master.tk
406 if name:
407 self._name = name
408 else:
409 self._name = 'PY_VAR' + repr(_varnum)
410 _varnum += 1
411 if value is not None:
412 self.initialize(value)
413 elif not self._tk.getboolean(self._tk.call("info", "exists", self._name)):
414 self.initialize(self._default)
415
416 def __del__(self):
417 """Unset the variable in Tcl."""

Callers

nothing calls this directly

Calls 5

_get_default_rootFunction · 0.85
_rootMethod · 0.80
initializeMethod · 0.45
getbooleanMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected