| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f7eda8e commit aa9a3cd
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -656,6 +656,9 @@ method on it, and to change its value you call the :meth:`!set` method. | |||
| 656 | 656 | If you follow this protocol, the widget will always track the value of the | |
| 657 | 657 | variable, with no further intervention on your part. | |
| 658 | 658 | ||
| 659 | + Keep a reference to the variable for as long as a widget uses it, for example | ||
| 660 | + by storing it as an attribute (see :class:`Variable`). | ||
| 661 | + | ||
| 659 | 662 | For example:: | |
| 660 | 663 | ||
| 661 | 664 | import tkinter as tk | |
@@ -5733,6 +5736,14 @@ Variable classes | |||
| 5733 | 5736 | :class:`StringVar`, :class:`IntVar`, :class:`DoubleVar` or | |
| 5734 | 5737 | :class:`BooleanVar` -- rather than :class:`!Variable` directly. | |
| 5735 | 5738 | ||
| 5739 | + .. note:: | ||
| 5740 | + | ||
| 5741 | + When a :class:`!Variable` is garbage collected, its Tcl variable is unset. | ||
| 5742 | + Keep a reference to it for as long as a widget is linked to it, for example | ||
| 5743 | + by storing it as an attribute rather than in a local variable. | ||
| 5744 | + Otherwise Tk recreates the Tcl variable to keep the widget working, but it | ||
| 5745 | + is never unset again, leaking one Tcl variable per dropped wrapper. | ||
| 5746 | + | ||
| 5736 | 5747 | .. versionchanged:: 3.10 | |
| 5737 | 5748 | Two variables now compare equal (``==``) only when they have the same | |
| 5738 | 5749 | name, are of the same class, and belong to the same Tcl interpreter. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments