[Tutor] Multiple muti-selection dropdown options

Pooja Bhalode poojabhalode11 at gmail.com
Thu Feb 23 17:25:31 EST 2017


Hi,

I am working on GUI where I have two dropdown menus in a Toplevel of the
main root. Here, both the dropdown menus have mutiple selection option and
thus, the selections can be taken as an input from the user and printed out
in the code.

The window shows as below:
[image: Inline image 1]
Whereas the code is:

simroot = Toplevel(root)
simroot.title("Simulation of experiments")

Label(simroot, text = "Displaying concentration profiles with respect to
time:").grid(row = 0, column = 0, sticky = W)

Label(simroot, text = "Select the experiments to be displayed: ").grid(row
= 1, column = 0, sticky = W)
varlist = StringVar()
varlist.set("Experiment1 Experiment2 Experiment3 Experiment4 Experiment5")
scroll1 = Scrollbar(simroot, orient = "vertical")
scroll1.grid(column = 2, sticky = W)

lstbox = Listbox(simroot, listvariable = varlist, selectmode = MULTIPLE,
yscrollcommand = scroll1.set, width = 20, height = 3)
lstbox.grid(row = 2, column = 1, sticky = W)
scroll1.config(command = lstbox.yview)

def selectexp():
newlist = list()
selection = lstbox.curselection()
for i in selection:
tempvar = lstbox.get(i)
newlist.append(tempvar)

for val in newlist:
print (val)


selectbutt = Button(simroot, text = "Submit", command = selectexp)
selectbutt.grid(row = 6,column = 1, sticky = W)
# Row 1 would print the name of the experiment selected and the species
displayed would be in row3.

Label(simroot, text = "Select concentration species:").grid(row = 7, column
= 0, sticky = W)
concvarlist = StringVar()
concvarlist.set("A B C D E")
scroll2 = Scrollbar(simroot, orient = "vertical")
scroll2.grid(column = 2, sticky = W)
lstbox2 = Listbox(simroot, listvariable = concvarlist, selectmode =
MULTIPLE, yscrollcommand = scroll2.set, width = 20, height = 3)
lstbox2.grid(row = 8, column = 1, sticky = W)
scroll2.config(command = lstbox2.yview)
def selectexp2():
newlist2 = list()
selection2 = lstbox2.curselection()
for i in selection2:
tempvar2 = lstbox2.get(i)
newlist2.append(tempvar2)

for val in newlist2:
print (val)
selectbutt = Button(simroot, text = "Submit", command = selectexp2)
selectbutt.grid(row = 9,column = 1, sticky = W)


def Submitplot():
print "Create plot"

Button(simroot, text = "Submit and Plot", command = Submitplot).grid(row =
10, column = 0, sticky = W)

However, the issue is that when the user selects options from the first
dropdown menu and moves on to selecting the second one, the first dropdown
selections are lost, is there a way to store the highlighted selections on
the display screen? In the code, I can get them printed and save the
selections, however I was looking for a way to keep them highlighted on the
screen as well for both the drop down menus.
Please let me know.
Thank you

Pooja


More information about the Tutor mailing list