GUI: Création d’une ListBox avec un ScrollBar

Author:

 list, list, map, set, tkinter
{filelink=15422}

from Tkinter import *
 
class Scrolled_List(Frame):
    def __init__(self, options, parent=None):
        Frame.__init__(self, parent)
        self.pack(expand=YES, fill=BOTH)
        self.paintComponent(options)
 
    def list_event(self, event):
        """ Evénement """
        # Obtenir l'index de l'élément sélectionné
        index = self.listbox.curselection( )
        # obtenir le texte de l'élément sélectionné
        text = self.listbox.get(index)
        print 'Vous avez sélectionné', text
 
    def paintComponent(self, options):
        """ Création des Composants """
        scroll_bar = Scrollbar(self)
        list = Listbox(self, relief=FLAT)
        scroll_bar.config(command=list.yview)
        list.config(yscrollcommand=scroll_bar.set)
        scroll_bar.pack(side=RIGHT, fill=Y)
        list.pack(side=LEFT, expand=YES, fill=BOTH)
        index = 0
        for elem in options:
            list.insert(index, elem)
            index += 1
        list.config(selectmode=SINGLE, setgrid=1)
        list.bind('<Double-1>', self.list_event)
        self.listbox = list
 
if __name__ == '__main__':
    options = map((lambda x: 'a' + str(x)), range(26))
    Scrolled_List(options).mainloop( )

Livres Sur ce Sujet

Apprendre à programmer avec Python 3 Apprenez à programmer en Python Python : Petit guide à l’usage du développeur agile Apprendre à programmer avec Python 3 : Avec plus de 50 pages de corigés d’exercices !

Leave a Reply

Your email address will not be published. Required fields are marked *


− 1 = three