root = Tk()
my_list = [[1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]]
var = IntVar()
var2 = IntVar()
var3 = IntVar()
def show():
if var.get() == 1:
fig, ax = plt.subplots()
y, x, _ = ax.hist(my_list[0], bins = 150)
if var2.get() == 1:
fig2, ax2 = plt.subplots()
y, x, _ = ax2.hist(my_list[1], bins = 150)
if var3.get() def checked(self):
return self.variable.get() == 1
== 1:
fig3, ax3 = plt.subplots()
y, x, _ = ax3.hist(my_list[2], bins = 150)
plt.show()
button = Button(root, text = "Show Histograms", command = show).pack()
c = Checkbutton(root, text = 'first list', variable = var).pack()
c2 = Checkbutton(root, text = 'second list', variable = var2).pack()
c3 = Checkbutton(root, text = 'third list', variable = var3).pack()
root.mainloop()
UPDATE: I managed to write it more compact but it does not work like that:
my_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
varChannels = []
checkbuttonChannels = []
def show():
for i in range(3):
if varChannels[i] == 1:
fig, ax = plt.subplots()
y, x, _ = ax2.hist(my_list[i], bins = 150)
plt.show()
for _ in range(3):
varChannels.append(IntVar())
checkbuttonChannels.append('0')
for i in range(3):
checkbuttonChannels[i] = Checkbutton(root, text = str(i), variable = varChannels[i]).pack()
button = Button(root, text = "Show Histograms", command = show).pack()
root.mainloop()