jeudi 16 avril 2020

Reading dynamic checkbox value in python

I have the following code where I wanted the values of the selected checkboxes to be displayed. But the output is empty. rxList contains ['CAR1','CAR2','CAR3']

and I want to build checkboxes with these values and return the selected values. I am not getting why it is not reading the selected checkox values

Any suggestions are highly appreciated

def getSelections(rxList):
    window = Tk()
    global selections
    selections =[]
    for i in rxList:
        sel = StringVar()
        selections.append(sel)  
        cb = Checkbutton(window, text = i, variable = sel, onvalue = i, offvalue="None")
        cb.pack()
    btn = Button(window,text = "Next", command = showme)
    # btn1 = Button(window,text= )
    btn.pack()
    print(selections)
    window.mainloop()

def showme():
    for i in range(len(selections)):
        print("---selected values----",selections[i].get())



Aucun commentaire:

Enregistrer un commentaire