Python Forum
[Tkinter] Completing Action when CheckBox is Checked
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
Reply
#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.
Reply
#3
Thank you so much! It works perfectly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get the value of a checkbox scratchmyhead 4 925 May-14-2020, 02:56 PM
Last Post: scratchmyhead
  Tkinter checkbox value scratchmyhead 5 1,308 May-09-2020, 11:44 PM
Last Post: menator01
  TreeviewWith CheckBox issac_n 1 4,263 Mar-08-2020, 06:51 AM
Last Post: shamnadinn
  tkinter checkbutton if checked MC2020 2 2,322 Jan-21-2020, 07:08 PM
Last Post: joe_momma
  Tkinter Checkbox niro_one 1 1,036 Jan-13-2020, 11:31 AM
Last Post: joe_momma
  Tkinter Buttons action d3fi 1 771 Nov-20-2019, 09:16 PM
Last Post: Larz60+
  [Tkinter] Unable to create checkbox and select at run time tej7gandhi 5 1,819 May-05-2019, 04:57 PM
Last Post: tej7gandhi
  Simple Button click on image file to create action? jpezz 4 2,906 Mar-27-2019, 10:08 PM
Last Post: jpezz
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 4,049 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  Displaying error in QTableview and with Checkbox in Column under macOsX nieselfriem 1 3,511 Mar-19-2017, 10:43 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020