Tkinter, Python, CheckBox, help solve how to check true or false?



  • I can't figure out how to check, that's the code:

    def show():
        print('флажок 18', setonstart_value.get())
        if (setonstart_value.get()):
            print('No')
    

    window = tk.Tk()
    setonstart_value = tk.StringVar()
    setonstart = tk.Checkbutton(window, text='SetOnStart',
    variable=setonstart_value,
    offvalue='No',
    onvalue='yes'
    )
    setonstart.pack()
    tk.Button(window, text='show', command=show).pack()
    window.mainloop()



  • You have a flank value - a line.'yes' or 'No') The empty line is considered to be the truth, so the condition is if (setonstart_value.get()): Always done.

    Make the variable. setonstart_value logical variableBooleanVar()) instead of string (StringVar()and clean up. onvalue and offvalue, then there'll be a black box. Falseon . True:

    import tkinter as tk
    

    def show():
    print('флажок 18', setonstart_value.get())
    if (setonstart_value.get()):
    print('Yes')
    else:
    print('No')

    window = tk.Tk()
    setonstart_value = tk.BooleanVar()
    setonstart = tk.Checkbutton(window, text='SetOnStart', variable=setonstart_value)
    setonstart.pack()
    tk.Button(window, text='show', command=show).pack()
    window.mainloop()

    Or leave. StringVarbut then you have to compare the specific value of the line, for example:

    if (setonstart_value.get() == 'yes'):
    print('Yes')
    else:
    print('No')



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2