Introduction
In this blog, I am going to create a checkbox widget in Python GUI application. It will display the checkbox's status on the application screen.
Software requirement
Python 3.5 and IDLE (Python 3.5)
Programming code
-
- import tkinter as tk
- from tkinter import ttk
- win = tk.Tk()
- win.title("Python GUI App")
-
- ttk.Label(win, text="Checkbox status :").grid(column=0,row=0)
-
-
- chVarDis=tk.IntVar()
- check1=tk.Checkbutton(win, text="Disabled", variable=chVarDis, state='disabled')
- check1.select()
- check1.grid(column=0,row=4, sticky=tk.W)
-
- chVarUn=tk.IntVar()
- check2=tk.Checkbutton(win, text="UnChecked", variable=chVarUn)
- check2.deselect()
- check2.grid(column=1,row=4, sticky=tk.W)
-
- chVarEn=tk.IntVar()
- check3=tk.Checkbutton(win, text="Enabled", variable=chVarEn)
- check3.select()
- check3.grid(column=2,row=4, sticky=tk.W)
-
- win.mainloop()
About the code
- First, import the tkinter module.
- Next, assign a class and variables and give application title.
- Next, create three checkboxes and its status.
- Finally, I have started the Windows event loop by calling the main loop method, then executed the code.
Output