On 23/02/17 22:25, Pooja Bhalode wrote: > I am working on GUI where I have two dropdown menus in a Toplevel of the > main root.
That's not what your code shows. It shows scrolling listboxes, not menus. But it seems like a Frame with a set of checkboxes would be closer to what you actually want? Anyway... > The window shows as below: > [image: Inline image 1] As I keep pointing out you cannot send images to this list, the server throws them away as potential security risks. > Whereas the code is: > > def selectexp(): > newlist = list() > selection = lstbox.curselection() > for i in selection: > tempvar = lstbox.get(i) > newlist.append(tempvar) > Note that in this function you create a list, populate it with values and then throw them all away. If you want to keep the values you need to declare the list as a global variable. > for val in newlist: > print (val) Because you are not posting in plain text I can't tell if those two lines are inside the previous function or not. I'm assuming they are inside the function? If not I'd expect a name error for newlist? > def selectexp2(): > newlist2 = list() > selection2 = lstbox2.curselection() > for i in selection2: > tempvar2 = lstbox2.get(i) > newlist2.append(tempvar2) > > for val in newlist2: > print (val) Same problem here, you declare newlist2 as a new list inside the function, then when the function exits it throws it away. If you want to access variables after the function exits you need to make them global (or start using classes and objects) > 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, See comments above. Make the lists global. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor