Re: [Tutor] Multiple muti-selection dropdown options
On 24/02/17 14:39, Pooja Bhalode wrote: > 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 Peter has given you the answer: you need to specify exportselection as False. What he didn't explain is why... The default behaviour is for the selections to be copied to the OS Windows selection mechanism, so when tyou move to a new widget and select something else the OS selection moves there and you lose the previous selection. This interchange between the OS selection and the Tkinter selection is the "export" bit of exportselection. By making it false the OS no longer grabs your selection and thus each widget is free to keep track of its own. The downside is you can no onger use your selection in any other window (eg paste it into a field). But for this example I doubt if that matters. BTW You may want to change selectionmode to EXTENDED Which shows the multiple selections more clearly - I think that will suit your needs better. -- 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
Re: [Tutor] Multiple muti-selection dropdown options
Pooja Bhalode wrote: > I am working on GUI where I have two dropdown menus in a Toplevel Actually your code shows two Listbox wigets. > 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? With the help of a search engine I found out that you need to specify listbox = Listbox(..., exportselection=False) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Multiple muti-selection dropdown options
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 <poojabhalod...@gmail.com> wrote: > > -- Forwarded message -- > From: Alan Gauld via Tutor <tutor@python.org> > Date: Thu, Feb 23, 2017 at 8:51 PM > Subject: Re: [Tutor] Multiple muti-selection dropdown options > To: tutor@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@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Multiple muti-selection dropdown options
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
[Tutor] Multiple muti-selection dropdown options
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor