Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes
tkinter.Variable Class Reference
Inheritance diagram for tkinter.Variable:
Inheritance graph
[legend]
Collaboration diagram for tkinter.Variable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __del__
def __str__
def set
def get
def trace_variable
def trace_vdelete
def trace_vinfo
def __eq__

Static Public Attributes

 trace = trace_variable

Private Attributes

 _master
 _tk
 _name

Static Private Attributes

string _default = ""

Detailed Description

Class to define value holders for e.g. buttons.

Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
that constrain the type of the value returned from get().

Definition at line 154 of file __init__.py.


Constructor & Destructor Documentation

def tkinter.Variable.__init__ (   self,
  master = None,
  value = None,
  name = None 
)
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.

Reimplemented in tkinter.BooleanVar, tkinter.DoubleVar, tkinter.IntVar, and tkinter.StringVar.

Definition at line 160 of file __init__.py.

00160 
00161     def __init__(self, master=None, value=None, name=None):
00162         """Construct a variable
00163 
00164         MASTER can be given as master widget.
00165         VALUE is an optional value (defaults to "")
00166         NAME is an optional Tcl name (defaults to PY_VARnum).
00167 
00168         If NAME matches an existing variable and VALUE is omitted
00169         then the existing value is retained.
00170         """
00171         global _varnum
00172         if not master:
00173             master = _default_root
00174         self._master = master
00175         self._tk = master.tk
00176         if name:
00177             self._name = name
00178         else:
00179             self._name = 'PY_VAR' + repr(_varnum)
00180             _varnum += 1
00181         if value is not None:
00182             self.set(value)
00183         elif not self._tk.call("info", "exists", self._name):
            self.set(self._default)

Here is the caller graph for this function:

def tkinter.Variable.__del__ (   self)
Unset the variable in Tcl.

Definition at line 184 of file __init__.py.

00184 
00185     def __del__(self):
00186         """Unset the variable in Tcl."""
        self._tk.globalunsetvar(self._name)

Member Function Documentation

def tkinter.Variable.__eq__ (   self,
  other 
)
Comparison for equality (==).

Note: if the Variable's master matters to behavior
also compare self._master == other._master

Definition at line 221 of file __init__.py.

00221 
00222     def __eq__(self, other):
00223         """Comparison for equality (==).
00224 
00225         Note: if the Variable's master matters to behavior
00226         also compare self._master == other._master
00227         """
00228         return self.__class__.__name__ == other.__class__.__name__ \
00229             and self._name == other._name

def tkinter.Variable.__str__ (   self)
Return the name of the variable in Tcl.

Definition at line 187 of file __init__.py.

00187 
00188     def __str__(self):
00189         """Return the name of the variable in Tcl."""
        return self._name
def tkinter.Variable.get (   self)
Return value of variable.

Reimplemented in tkinter.BooleanVar, tkinter.DoubleVar, tkinter.IntVar, and tkinter.StringVar.

Definition at line 193 of file __init__.py.

00193 
00194     def get(self):
00195         """Return value of variable."""
        return self._tk.globalgetvar(self._name)

Here is the caller graph for this function:

def tkinter.Variable.set (   self,
  value 
)
Set the variable to VALUE.

Reimplemented in tkinter.IntVar.

Definition at line 190 of file __init__.py.

00190 
00191     def set(self, value):
00192         """Set the variable to VALUE."""
        return self._tk.globalsetvar(self._name, value)

Here is the caller graph for this function:

def tkinter.Variable.trace_variable (   self,
  mode,
  callback 
)
Define a trace callback for the variable.

MODE is one of "r", "w", "u" for read, write, undefine.
CALLBACK must be a function which is called when
the variable is read, written or undefined.

Return the name of the callback.

Definition at line 196 of file __init__.py.

00196 
00197     def trace_variable(self, mode, callback):
00198         """Define a trace callback for the variable.
00199 
00200         MODE is one of "r", "w", "u" for read, write, undefine.
00201         CALLBACK must be a function which is called when
00202         the variable is read, written or undefined.
00203 
00204         Return the name of the callback.
00205         """
00206         cbname = self._master._register(callback)
00207         self._tk.call("trace", "variable", self._name, mode, cbname)
        return cbname
def tkinter.Variable.trace_vdelete (   self,
  mode,
  cbname 
)
Delete the trace callback for a variable.

MODE is one of "r", "w", "u" for read, write, undefine.
CBNAME is the name of the callback returned from trace_variable or trace.

Definition at line 209 of file __init__.py.

00209 
00210     def trace_vdelete(self, mode, cbname):
00211         """Delete the trace callback for a variable.
00212 
00213         MODE is one of "r", "w", "u" for read, write, undefine.
00214         CBNAME is the name of the callback returned from trace_variable or trace.
00215         """
00216         self._tk.call("trace", "vdelete", self._name, mode, cbname)
        self._master.deletecommand(cbname)
Return all trace callback information.

Definition at line 217 of file __init__.py.

00217 
00218     def trace_vinfo(self):
00219         """Return all trace callback information."""
00220         return [self._tk.split(x) for x in self._tk.splitlist(
            self._tk.call("trace", "vinfo", self._name))]

Member Data Documentation

string tkinter.Variable._default = "" [static, private]

Reimplemented in tkinter.BooleanVar, tkinter.DoubleVar, tkinter.IntVar, and tkinter.StringVar.

Definition at line 159 of file __init__.py.

Definition at line 173 of file __init__.py.

Definition at line 176 of file __init__.py.

Definition at line 174 of file __init__.py.

Definition at line 208 of file __init__.py.


The documentation for this class was generated from the following file: