"""Demonstrate the various selection modes of a listbox.""" from Tkinter import * class App: def __init__(self, parent): self.parent = parent self.create_widgets() def create_widgets(self): self.listbox1 = Listbox(self.parent, width=20, height=10, exportselection=0) self.listbox1.pack(expand=1, fill=BOTH) self.radios = [] self.v_mode = StringVar() self.v_mode.set(self.listbox1['selectmode']) for mode in ['single', 'browse', 'multiple', 'extended']: b = Radiobutton(self.parent, text=mode, value=mode, variable=self.v_mode, anchor=W, command=self.set_it) b.pack(fill=X) for line in ['one', 'two', 'three', 'four', 'five']: self.listbox1.insert(END, line) def set_it(self): self.listbox1.config(selectmode=self.v_mode.get()) # Boilerplate from here on... if __name__ == '__main__': root = Tk() app = App(root) root.mainloop()