mardi 14 février 2017

Python Tkinter - Get value from mutliple checkboxes

I am creating a Tkinter application where trying to get value from multiple checkboxes. I am able to create the checkboxes but not able to retrieve the value .i.e. checked or not checked checkboxes.

Requirement:

I need to loop through all checkbox variables to identify the checked ones.

import openpyxl
import sys
import pandas as pd
from Tkinter import *
import ttk
import tkFont


reload(sys)
sys.setdefaultencoding('utf8')

top = Tk()
notebook = ttk.Notebook(top)
notebook.grid(row=1, column=0, columnspan=1, sticky=W)
frame1 = ttk.Frame(top)
notebook.add(frame1, text='TAB1')
s = ttk.Style()
s.theme_use('clam')
helv36 = tkFont.Font(family='Helvetica', size=12, weight=tkFont.BOLD)

wb = openpyxl.load_workbook('File',data_only=True)
ws = wb['Sheet1']

mylist = []
mylist1 = []
for col in ws['A']:
     mylist.append(col.value)
for col in ws['B']:
    mylist1.append(col.value)

mylist = [str(item) for item in mylist]
mylist1 = [str(item) for item in mylist1]

i=2
for name in mylist:
    Label(frame1, text="col1",
          borderwidth=1,font=helv36).grid(row=1)
    Label(frame1, text=name,
                  borderwidth=1).grid(row=i)
    i +=1


i =2
for name in mylist1:
    Label(frame1, text="col2",
          borderwidth=1,font=helv36).grid(row=1, column=1)
    Label(frame1, text=name,
          borderwidth=1).grid(row=i,column=1)
    val = IntVar()
    val = "v" + str(i)
    c_val = Checkbutton(frame1, variable=val)
    c_val.grid(row=i, column=2,sticky = W)
    i +=1


***def chkbox_checked():
    #Need to loop to get checked checkboxes***


B200 = Button(frame1, text ="Check", command = chkbox_checked,font=helv36, bg='orange')
B200.grid(row=100)
top.mainloop()




Aucun commentaire:

Enregistrer un commentaire