About Lesson
In this TKinter Tutorial we are going to learn creating TKinter CheckBox, A checkbox is a GUI widget that permits the user to make a binary choice, i.e. a choice between one of two possible mutually exclusive options.
This is the complete code for this lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from tkinter import * from tkinter import ttk class Window(Tk): def __init__(self): super(Window, self).__init__() self.title("Check Buttons In TKinter") self.minsize(500,400) self.wm_iconbitmap("myicon.ico") self.create_checkbuttons() def create_checkbuttons(self): check1 = ttk.Checkbutton(self, text = "Disabled", state = "disabled") check1.grid(row = 0, column = 0) check2 = ttk.Checkbutton(self, text="Unchecked") check2.grid(row=0, column=1) check3 = ttk.Checkbutton(self, text="Enabled") check3.grid(row=0, column=2) window = Window() window.mainloop() |
You can use ttk.checbutton() for creating checkbox or checkbutton, also you can pass different parameters like the text of checkbox and also the state of checkbox.
1 |
ttk.Checkbutton(self, text = "Disabled", state = "disabled") |
Also we are going to add our checkbutton in a grid layout.
1 |
check1.grid(row = 0, column = 0) |
Run the complete code and this will be the result.