Connection and values

I have the following code snippet:

def toggle_label_place():
    global label_visible

    if label_visible:
        label_visible = False
        znacka.place_forget()
    else:
        label_visible = True
        znacka.place(relx=0.5, rely=0.5, anchor="center")

How is label_visible connected to znacka variable? What I can read from it is, that label_visible can have two Boolean values and that’s it. I would expect that label_visible should be connected to znacka and should be able to read its state or the state of its geometry manager. But I don’t see the connection, nor the mechanism, how it works.

Hey Jan from the look of things I see the connection that label_visible has, is that its acting like a flag which determines the znacka object’s visibility.

This code is the mechanism :slight_smile:

 if label_visible:
     label_visible = False
     znacka.place_forget()
 else:
     label_visible = True
     znacka.place(relx=0.5, rely=0.5, anchor="center")

As Michael Mmbaya says, label_visible is the control flag, but you
kind of know that.

However, instead of znacka knowing to consult this flag (which I’m
inferring is what you expect), the code above consults the flag. And
then tells the znacka widget to place or forget.

So there’s nothing wired to znacka which references the flag; this
function is the wiring.

If you fiddle with the flag elsewhere, I’d not expect znacka to change
its state. It is the call to the toggle function which does that, and
nothing will do that automatically unless the toggle function itself is
wired to something eg as a callback for some button etc.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like