Bottom Page

Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Completing Action when CheckBox is Checked
#1
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
Quote
#2
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()
99 percent of computer problems exists between chair and keyboard.
hobby-programmer.com
Quote
#3
Thank you so much! It works perfectly.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter Buttons action d3fi 1 104 Nov-20-2019, 09:16 PM
Last Post: Larz60+
  [Tkinter] Unable to create checkbox and select at run time tej7gandhi 5 545 May-05-2019, 04:57 PM
Last Post: tej7gandhi
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 1,627 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  TreeviewWith CheckBox issac_n 0 1,544 Jun-05-2018, 03:56 PM
Last Post: issac_n
  Displaying error in QTableview and with Checkbox in Column under macOsX nieselfriem 1 2,348 Mar-19-2017, 10:43 PM
Last Post: nilamo
  doing something after been checked a checkbutton gray 1 1,517 Feb-18-2017, 05:11 PM
Last Post: Axel_Erfurt

Forum Jump:


Users browsing this thread: 1 Guest(s)