Value holder for boolean variables.
| 637 | |
| 638 | |
| 639 | class BooleanVar(Variable): |
| 640 | """Value holder for boolean variables.""" |
| 641 | _default = False |
| 642 | |
| 643 | def __init__(self, master=None, value=None, name=None): |
| 644 | """Construct a boolean variable. |
| 645 | |
| 646 | MASTER can be given as master widget. |
| 647 | VALUE is an optional value (defaults to False) |
| 648 | NAME is an optional Tcl name (defaults to PY_VARnum). |
| 649 | |
| 650 | If NAME matches an existing variable and VALUE is omitted |
| 651 | then the existing value is retained. |
| 652 | """ |
| 653 | Variable.__init__(self, master, value, name) |
| 654 | |
| 655 | def set(self, value): |
| 656 | """Set the variable to VALUE.""" |
| 657 | return self._tk.globalsetvar(self._name, self._tk.getboolean(value)) |
| 658 | |
| 659 | initialize = set |
| 660 | |
| 661 | def get(self): |
| 662 | """Return the value of the variable as a bool.""" |
| 663 | try: |
| 664 | return self._tk.getboolean(self._tk.globalgetvar(self._name)) |
| 665 | except TclError: |
| 666 | raise ValueError("invalid literal for getboolean()") |
| 667 | |
| 668 | |
| 669 | def mainloop(n=0): |
no outgoing calls
searching dependent graphs…