I've made an array of checkboxes in my tkinter application which gets appended to, whenever a plot is made, in order to hide/show each of them. However, the plot hides just fine, but never shows when the checkbox is clicked again. I'm assuming this is because the variable is refusing to update:
self.vararray.append(tk.IntVar(value=0))
cntr = self.plot_counter
c = tk.Checkbutton(self.checkbox_frame,selectcolor="#F194EA", text=tail[:-4], variable=self.vararray[-1],command= lambda var=cntr: self.hide_plot(filename, visible = self.vararray[cntr]))
c.pack(side=tk.LEFT)
c.var = self.vararray[-1]
self.btnarray.append(c)
self.plot_counter+=1
I have gone through other answers and I've even made sure to append the variables and checkboxes in an array, but to no avail. The relevant code for hiding the plot is here:
def hide_plot(self, filename, visible):
if(visible.get() == 0):
for i in range(0, len(self.plotarray)):
if self.filearray[i] == filename:
for j in range(0, len(self.plotarray[i])):
self.plotarray[i][j].set_visible(False)
#visible.set(1)
else:
for i in range(0, len(self.plotarray)):
if self.filearray[i] == filename:
for j in range(0, len(self.plotarray[i])):
self.plotarray[i][j].set_visible(True)
#visible.set(0)
self.fig.canvas.draw()
I have to manually set the variable inside of the function in order for it to start working, what am I doing wrong here? Thanks!