- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I get the 'state' of a Tkinter Checkbutton?
Tkinter provides a variety of input widgets such as entry widget, text widget, listbox, combobox, spinbox, checkbox, etc. Checkboxes are used for taking validity input and the state gets active whenever the user clicks on the checkbutton. In terms of a particular application, we can check the state of the tkinter CheckButtons by using the state() method. It prints the actual state of the tkinter checkbuttons.
#Import the required library from tkinter import* from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x250") #Define geometry of the window win.geometry("750x250") #Create CheckButtons chk= ttk.Checkbutton(win, text="Python") chk.pack() chk.config(state=NORMAL) print(chk.state()) win.mainloop()
Running the example code will display a window with a check button that is initially defined as normal state.
Now, remove the line "win.mainloop()" from the program to print the state of the checkbox on the console.
- Related Articles
- How do I get the background color of a Tkinter Canvas widget?
- How do I get the width and height of a Tkinter window?
- How do I get rid of the Python Tkinter root window?
- How to disable checkbutton Tkinter (grey out)?
- How to disable (grey out) a checkbutton in Tkinter?
- How do I close a tkinter window?
- How do I change the overall theme of a tkinter application?
- How do I change the background of a Frame in Tkinter?
- Making Menu options with Checkbutton in Tkinter?
- How do I get an event callback when a Tkinter Entry widget is modified?
- How do I position the buttons on a Tkinter window?
- How to detect when an OptionMenu or Checkbutton changes in Tkinter?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I create a date picker in tkinter?