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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
#
try:
import Tkinter as Tk
except:
import tkinter as Tk
root = Tk.Tk()
root.title("L'option exportselection avec les Widgets Entry et Listbox")
Tk.Label(root, text='exportselection=1').grid(row=0, column=1, padx=5, pady=5, sticky=Tk.E+Tk.W)
Tk.Label(root, text='Listbox exportselection=1\nEntry exportselection=0').grid(row=0, column=2, padx=5, pady=5, sticky=Tk.E+Tk.W)
Tk.Label(root, text='exportselection=0').grid(row=0, column=3, padx=5, pady=5, sticky=Tk.E+Tk.W)
Tk.Label(root, text='Listbox exportselection=0\nEntry exportselection=1').grid(row=0, column=4, padx=5, pady=5, sticky=Tk.E+Tk.W)
Tk.Label(root, text='Listbox').grid(row=1, column=0, padx=5, pady=5)
Tk.Label(root, text='Selection dans\nla Lisbox').grid(row=2, column=0, padx=5, pady=5)
Tk.Label(root, text="'Clipboard'/Sélection\nselection_get() sur la Listbox").grid(row=3, column=0, padx=5, pady=5)
Tk.Label(root, text='Entry (un clic/deux clics)').grid(row=4, column=0, padx=5, pady=5)
# exportselection=1
lb1 = Tk.Listbox(root, selectmode=Tk.SINGLE)
lb1.grid(row=1, column=1, padx=5, pady=5)
l1 = Tk.Label(root, bg='white')
l1.grid(row=2, column=1, padx=5, pady=5, sticky=Tk.E+Tk.W)
lr1 = Tk.Label(root, bg='yellow')
lr1.grid(row=3, column=1, padx=5, pady=5, sticky=Tk.E+Tk.W)
e1 = Tk.Entry(root)
e1.grid(row=4, column=1, padx=5, pady=5)
e1.insert(0, '11111')
for item in ['un', 'deux', 'trois', 'quatre', 'cinq']:
lb1.insert(Tk.END, item)
# Listbox exportselection=1 / Entry exportselection=0
lb2 = Tk.Listbox(root, selectmode=Tk.SINGLE)
lb2.grid(row=1, column=2, padx=5, pady=5)
l2 = Tk.Label(root, bg='white')
l2.grid(row=2, column=2, padx=5, pady=5, sticky=Tk.E+Tk.W)
lr2 = Tk.Label(root, bg='yellow')
lr2.grid(row=3, column=2, padx=5, pady=5, sticky=Tk.E+Tk.W)
e2 = Tk.Entry(root, exportselection=0)
e2.grid(row=4, column=2, padx=5, pady=5)
e2.insert(0, '22222')
for item in ['uno', 'dos', 'tres', 'cuatro', 'cinco']:
lb2.insert(Tk.END, item)
# exportselection=0
lb3 = Tk.Listbox(root, exportselection=0, selectmode=Tk.SINGLE)
lb3.grid(row=1, column=3, padx=5, pady=5)
l3 = Tk.Label(root, bg='white')
l3.grid(row=2, column=3, padx=5, pady=5, sticky=Tk.E+Tk.W)
lr3 = Tk.Label(root, bg='yellow')
lr3.grid(row=3, column=3, padx=5, pady=5, sticky=Tk.E+Tk.W)
e3 = Tk.Entry(root, exportselection=0)
e3.grid(row=4, column=3, padx=5, pady=5)
e3.insert(0, '33333')
for item in ['one', 'two', 'three', 'four', 'five']:
lb3.insert(Tk.END, item)
# Listbox exportselection=0 / Entry exportselection=1
lb4 = Tk.Listbox(root, exportselection=0, selectmode=Tk.SINGLE)
lb4.grid(row=1, column=4, padx=5, pady=5)
l4 = Tk.Label(root, bg='white')
l4.grid(row=2, column=4, padx=5, pady=5, sticky=Tk.E+Tk.W)
lr4 = Tk.Label(root, bg='yellow')
lr4.grid(row=3, column=4, padx=5, pady=5, sticky=Tk.E+Tk.W)
e4 = Tk.Entry(root)
e4.grid(row=4, column=4, padx=5, pady=5)
e4.insert(0, '44444')
for item in ['eins', 'zwei', 'drei', 'vier', 'fünf']:
lb4.insert(Tk.END, item)
def isselect(event=None):
# curselection()
for lisb, lab in ((lb1, l1), (lb2, l2), (lb3, l3), (lb4, l4)):
try:
lab.config(text=lisb.get(lisb.curselection()))
except Tk.TclError:
lab.config(text='Pas de selection')
# selection_get() sur la Listbox
for lb, l in ((lb1, lr1), (lb2, lr2), (lb3, lr3), (lb4, lr4)):
try:
l.config(text=lb.selection_get())
except Tk.TclError:
l.config(text='Vide')
for Widget in (e1, lb1, e2, lb2, e3, lb3, e4, lb4):
Widget.bind('<ButtonRelease-1>', isselect)
Tk.Button(root, text='Quitter', command=root.quit).grid(row=4, column=5, padx=5, pady=5)
root.mainloop() |
Partager