I am creating the checkbuttons here:
var = []
k=0
for i in results:
var.append(IntVar())
Checkbutton(frame, text = i[0], variable = var[k], wraplength=500).pack()
k+=1
Here, I have obtained the variable for each check button and want to print the text of the checkbuttons that are checked:
# function is called when a button is clicked
def delHist():
for i in range(len(var)):
if var[i].get()==1: # checking if the checkbutton is checked
# want to print the text in the checkbutton here
How can I print the text of that checkbutton using only the variable?
Edit: The question here seems to be similar: How to get the text from a checkbutton in python ? (Tkinter)
I tried assigning Checkbutton(frame, text = i[0], variable = var[k], wraplength=500).pack()
to a list ch[p]
so as it iterates, it's assigned to a new object. When I added print ch[p].get()
under the function, I get an error.
I also tried print ch[p].get('text')
but I get the error
TypeError: "get()" takes 1 positional argument but 2 were given