Python Forum

Full Version: Completing Action when CheckBox is Checked
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
text1 = Checkbutton (root, text = "Text")
text1.place(x = 100, y = 290)

if text1.isChecked():
print("Hi")

This is the code I am trying to run. I want my code to go into the if statement whenever the checkbox is checked, if it gets unchecked and then checked again, I want it to go back into the if statement. Right now it is not doing anything. How can I get it to work?

Thank you! Huh
import tkinter as tk

class App:
    def __init__(self):
        self.root = tk.Tk()
        self.frame = tk.Frame(self.root)
        self.frame.pack()
        self.check_var = tk.IntVar()
        self.check_button = tk.Checkbutton(self.frame,
            command=self.check_status,
            variable=self.check_var,
            text="Text")

        self.check_button.pack()

    def check_status(self):
        print(self.check_var.get())

app = App()
app.root.mainloop()
Thank you so much! It works perfectly.