I use tkinter Checkbutton to get the information needed and my scripts are:
from tkinter import *
from tkinter.filedialog import askopenfilenames
window = Tk()
window.title('File Viewer')
frm=Frame(window)
filelist=[]
def selectfiles():
files=askopenfilenames(initialdir="D:\\Document", title="Select files")
fileList = window.tk.splitlist(files)
filelist.append(fileList)
btn = Button(frm,text='Select Files',command=selectfiles)
frm.pack()
btn.pack(side=RIGHT, fill=BOTH)
Heads = {'Head A': "HeadAEPTrend1 (Float)", 'Head B': "HeadBEPTrend1 (Float)"}
head_list=[]
for (key, value) in Heads.items():
strVar = StringVar()
head_list.append(strVar)
cb = Checkbutton(frm, text=key, variable=strVar, onvalue=value, offvalue='NA')
cb.pack(anchor=W)
parameters=[strvar.get() for strvar in head_list if strvar.get() != 'NA']
window.mainloop()
There are 2 things I did not expected:
- In the GUI the default is both head A and head B are selected.(I want the default is both heads not selected)
- I can only get
['','']
when I callparameters
in the shell after I closed the GUI.
Anyone knows what's going wrong?