1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# -*- coding:utf-8 -*-
from Tkinter import *
root=Tk()
root.geometry("400x400")
root.title("ListBox Sélection - v.3")
def focusSortie(event):
print "\n------\nSortie de Focus"
def focusEntree(event):
print "\n------\nEntree de Focus"
def focusSelection(event):
laselection = lis.curselection()
print "\n------\nSelection dans la listbox :"
print "selection get(ACTIVE) : ", lis.get(ACTIVE)
print "selection index(ACTIVE) : ", lis.index(ACTIVE)
print "selection get(ANCHOR) : ", lis.get(ANCHOR)
print "selection index(ANCHOR) : ", lis.index(ANCHOR)
print "selection la liste : ", laselection
def selectionSingle():
lis.select_clear(0,END)
lis.config(selectmode=SINGLE)
barreEtat.config(text="Sélection Single")
def selectionBrowse():
lis.select_clear(0,END)
lis.config(selectmode=BROWSE)
barreEtat.config(text="Sélection Browse")
def selectionMultiple():
lis.select_clear(0,END)
lis.config(selectmode=MULTIPLE)
barreEtat.config(text="Sélection Multiple")
def selectionExtended():
lis.select_clear(0,END)
lis.config(selectmode=EXTENDED)
barreEtat.config(text="Sélection Extended")
frame = Frame(root, padx=20, pady=20)
frame.pack(side=TOP, fill=BOTH, expand=1)
bo1 = Button(frame, text="Sélection single", command=selectionSingle)
bo2 = Button(frame, text="Sélection browse", command=selectionBrowse)
bo3 = Button(frame, text="Sélection multiple", command=selectionMultiple)
bo4 = Button(frame, text="Sélection extended", command=selectionExtended)
scr = Scrollbar(frame)
lis = Listbox(frame, selectmode=SINGLE, bg='ivory')
barreEtat = Label(frame, text="Départ : single", bd=1, relief=SUNKEN, anchor=W)
barreEtat.pack(side=BOTTOM, fill=X, pady=4)
bo1.pack(side=TOP, fill=X, pady=4)
bo2.pack(side=TOP, fill=X, pady=4)
bo3.pack(side=TOP, fill=X, pady=4)
bo4.pack(side=TOP, fill=X, pady=4)
scr.pack(side=RIGHT, fill=Y)
lis.pack(side=LEFT, fill=BOTH, expand=1)
scr.config(command=lis.yview)
lis.config(yscrollcommand=scr.set)
for i in range(30):
lis.insert(END, str(i)+"-"+str(i)+"-"+str(i))
lis.bind("<FocusOut>", focusSortie)
lis.bind("<FocusIn>", focusEntree)
lis.bind("<<ListboxSelect>>", focusSelection)
root.mainloop() |
Partager