[Python] Tkinter Checkbutton doesn't change my variable

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to use a Checkbutton with a function, my_var never changes but it always call my function.

    here the code:

    my_var = False
    def controllo_carta():
    global my_var
    print str(my_var)

    [...]

    c = tk.Checkbutton(toolbar, text="press me",onvalue=True,offvalue=False,variable=my_var,command=controllo_carta)
    c.select()
    c.pack(side=tk.LEFT,padx=2,pady=2)

    print 'my var:' + str(my_var)

    [...]


    where is my mistake?

    thanks!

    Continue reading...

Compartilhe esta Página