Python Program on Tkinter Checkbutton

Python course with 57 real-time projects - Learn Python

Program 1

from tkinter import *
class MyCheck:
 def __init__(self,myroot):
     self.mf=Frame(myroot,width=500,height=500,bg='cyan')
     self.mf.pack()
     self.mf.propagate(0)
     self.v1=IntVar()
     self.mychk=Checkbutton(self.mf,text='RedColor',variable=self.v1,bg='cyan',fg='red',font=('Algerian',10,'bold'),command=self.myClick)
     self.mychk.pack()

 def myClick(self):
    #print(self.v1.get())
    if(self.v1.get()==1):
        self.mf['bg']='red'
    if(self.v1.get()==0):
        self.mf['bg'] = 'cyan'


#Calling Place
myroot=Tk()
myroot.title("Checkbox Demo")
myroot.geometry('500x500')
myroot.wm_iconbitmap('2.ico')

M1=MyCheck(myroot)

myroot.mainloop()

 

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *