Changing tkinter variable inside its observer callback

I think that I do not quite understand when the tkinter variable notifies the observer, and when not. In particular, I do not understand why the following example calls only fonce:

from tkinter import Tk, IntVar

Tk()

x = IntVar()

def f(*_):
   print("f called")
   x.set(1)

x.trace("w", f)
x.set(0)
print(x.get())

I expect it to either stop responding during printing f calledtime and time again, or throw an exception at some point. Instead, it prints f calledexactly once, prints 1and exits.

+4
source share
1 answer

, , , . , , .

tcl/tk trace man. . commandPrefix :

commandPrefix , . , , commandPrefix, , commandPrefix ( ). , commandPrefix , .

+4

Source: https://habr.com/ru/post/1693381/


All Articles