mardi 22 octobre 2019

Checkbox values not being updated in tkinter

I'm pretty new to python and trying to create a GUI using tkinter for a program (manipulating csv files). I will have file names in a list, I need checkboxes corresponding to these files which I have accomplished using the below code. The only hurdle now is getting the state of the checkbox into another dict/list which I can use further down the code. Any help would be appreciated. Partial code below. Also getting an error while trying to extract values of the checkboxes in click6()

from tkinter import *

window0 = Tk()

chkstate2 = []
fileNAMES3 = ['a', 'b', 'c'] 
intvar_dict = {}
intvar_dict = dict.fromkeys(intvar_dict, 0)

def click2():
    window7 = Tk()
    window7.title("Choose files to plot")

    for in1c, in2c in enumerate(fileNAMES3[:], start = 0):
        intvar_dict[in2c] = IntVar()
        chk = Checkbutton(window7, text=fileNAMES3[in1c], var=intvar_dict[in2c], onvalue=1)
        chk.grid(column=0, row=in1c)

    def click6():       
        for a,b in enumerate(intvar_dict[:], start=0):
            if intvar_dict[b].get() > 0:
                chkstate2.append(intvar_dict[b])
        window7.destroy()

    btn7 = Button(window7, text="OK",command=click6)
    btn7.grid(column=0, row=in1c+1,padx=10, pady=10)
    btn7.config(height = 2, width = 20 )

btn2 = Button(window0, text="Choose", command=click2)
btn2.grid(column=2, row=7,padx=20, pady=5)

window0.mainloop()



Aucun commentaire:

Enregistrer un commentaire