2

I am having a strange problem using a tkinter listbox. My GUI also has an entry field, and when the value in the entry field is selected by click and drag the listbox selections are deselected. The below code recreates the issue in entirety. I run python 2.7 on windows.

import Tkinter as Tkinter

class window(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        self.grid()
        self.columnconfigure(0, minsize=200)

        self.LB = Tkinter.Listbox(self, bg='white',height=3, selectbackground='blue',relief='groove',selectmode='multiple')
        self.LB.grid(row=0, column=0, sticky='NSEW')
        self.LB.insert(1, '1')
        self.LB.insert(2, '2')            
        self.LB.insert(3, '3')
        self.LB.selection_set(0)
        self.LB.selection_set(2)

        self.E_var = Tkinter.StringVar()
        self.E = Tkinter.Entry(self, textvariable=self.E_var)
        self.E.grid(column=0, row=1, sticky='NSEW')
        self.E_var.set("'Click and drag' select me!")

if __name__ == "__main__":
    app = window(None)
    app.title('Window')
    app.mainloop()
John Crow
  • 927
  • 3
  • 13
  • 26
  • 2
    Sidenote: the use of `import x as x` is sanctioned by the Redundancy Department of Redundancy. – jonrsharpe Sep 16 '14 at 13:32
  • Thanks @jonrsharpe. The use of `exportselection=0` does indeed solve the problem. I'm not sure of the rules of stackoverflow, but if two different questions share the same answer are they still duplicate? – John Crow Sep 16 '14 at 13:44
  • 1
    Per the [Help Center](http://stackoverflow.com/help/duplicates), *"The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place."* There is no point in duplicating the content of the other answer here, although there is a point to this question remaining in place as a "signpost" to the original. – jonrsharpe Sep 16 '14 at 13:48

0 Answers0