I have created a class of tkinter where checkbutton is created while calling function checkbutton_create
method. It is invocating happens during initialization of class inside loop.
for k,v in df.items():
self.checkbutton_create(k)
I from start do not know how many checkbuttons will be created, it is depended on user's input inside file.
I have put a command function which will see state change in any of checkbutton and if it is 1 it will append the text of checkbutton to class list cls_list_checkbtn = []
class UsrApp():
df=None
cls_list_checkbtn = []
def __init__(self):
self.root=Tk()
self.root.title('Gmail Rotater Bulk EmailSender')
#frame for email checkbuttons
self.frm_checkbuttons=Frame(master=self.root,relief=SUNKEN,borderwidth=3)
self.frm_checkbuttons.pack(side='top',expand=YES,fill=X)
#checkbutton instantiations
df=pd.read_json('Email_Addresses/emailaddresses.json')
self.list_checkbtn=[]
self.dict_emails={}
self.count=0
for k,v in df.items():
self.checkbutton_create(k)
self.dict_emails[self.count]=k
self.count +=1
def checkbutton_create(self,txt):
self.wdgt_var = IntVar()
self.wdg_checkbutton = tkinter.Checkbutton(master=self.frm_checkbuttons, text=txt, variable=self.wdgt_var, command=self.checkbtn_add_list_text_values(txt,self.wdgt_var.get()))
self.wdg_checkbutton.pack(side='left',expand=YES,fill=X)
def checkbtn_add_list_text_values(self,txt,var_text):
print(var_text)
if var_text==1:
self.list_checkbtn.append(txt)
self.cls_list_checkbtn(txt)
I slightly changed code, added command to checkbuttons which have to fixture a state change in checkbutton value. But it only works when class is instantiated..
I was expecting every time state of checkbutton changes function checkbtn_add_list_text_values
fixture it and append text value to list.
But it only fixture when class is instantiated