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
  [closed] "checked" variable (attribute?) origin? paul18fr 4 371 Mar-05-2024, 04:20 PM
Last Post: deanhystad
  [PyQt] choose checkbox devilonline 1 1,239 Feb-17-2023, 01:23 PM
Last Post: Axel_Erfurt
  [Tkinter] Dynamic checkbox treeview issue OogieM 8 4,820 Mar-20-2022, 02:10 PM
Last Post: OogieM
  tkinter change the text of the checkbox zazas321 1 3,759 Sep-17-2021, 06:19 AM
Last Post: zazas321
  How to get the value of a checkbox scratchmyhead 4 2,996 May-14-2020, 02:56 PM
Last Post: scratchmyhead
  Tkinter checkbox value scratchmyhead 5 3,594 May-09-2020, 11:44 PM
Last Post: menator01
  TreeviewWith CheckBox issac_n 1 7,686 Mar-08-2020, 06:51 AM
Last Post: shamnadinn
  tkinter checkbutton if checked MC2020 2 5,925 Jan-21-2020, 07:08 PM
Last Post: joe_momma
  Tkinter Checkbox niro_one 1 2,312 Jan-13-2020, 11:31 AM
Last Post: joe_momma
  Tkinter Buttons action d3fi 1 1,979 Nov-20-2019, 09:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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