[Tutor] Multiple muti-selection dropdown options

Pooja Bhalode poojabhalode11 at gmail.com
Fri Feb 24 09:39:52 EST 2017


Hi Alan,

Thank you for your inputs. I made the lists global in the Toplevel root. I
still have the problem where in if I select few options from the first
list, and then move to the next list, I loose the selections made on the
screen in the first list. I can however print it out and store it in the
code, but I would like to show it on the screen as well as highlighted even
after moving to the next list. Can you please tell me if there is a way?
Sorry about inserting the images, I was unaware of that and also regarding
some of my nomenclature mistakes, still learning :)

Thank you

Pooja

On Thu, Feb 23, 2017 at 10:37 PM, Pooja Bhalode <poojabhalode11 at gmail.com>
wrote:

>
> ---------- Forwarded message ----------
> From: Alan Gauld via Tutor <tutor at python.org>
> Date: Thu, Feb 23, 2017 at 8:51 PM
> Subject: Re: [Tutor] Multiple muti-selection dropdown options
> To: tutor at python.org
>
>
> 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 at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list