30numbers = (
"Uno",
"Due",
"Tre",
"Quattro",
"Cinque",
"Sei",
"Sette",
"Otto",
31 "Nove",
"Dieci",
"Undici",
"Dodici",
"Tredici",
"Quattordici")
33modes = (
"single",
"browse",
"multiple",
"extended")
35explmodes = (
"single mode : you can select only one item at once, clicking on it in the listbox",
36 "browse mode : you can select only an item at once, clicking on it or dragging with the mouse",
37 "multiple mode : you can select multiple items, clicking on them; clicking on a selected item " +
39 "extended mode : you can select multiple items, clicking, dragging the mouse and using the" +
40 "<CTRL> or <SHIFT> keys")
44 """Adds an item to the left listbox and controls
45 the state of ButAdd and ButDel.
"""
46 nitems = lstTest.size()
47 if nitems < len(numbers):
48 lstTest.add(numbers[nitems])
49 nitems = lstTest.size()
52 if nitems == len(numbers):
56 """ Deletes an item from the left listbox and controls
57 the state of ButAdd and ButDel.
"""
58 nitems = lstTest.size()
60 lstTest.delete(nitems - 1)
63 nitems = lstTest.size()
64 if nitems < len(numbers):
66 if lstTest.size() == 0:
71def lbox_changed(event):
72 """Callback called when you select one or more item in the left listbox."""
73 sel = lstTest.get_selected()
82 labSel.set_content(
"Selected index: " + s
if len(sel) <= 1
else "Selected indexes: " + s)
84def mode_changed(event):
85 """Callback called when the user modifies the selection mode."""
88 sel = lstMode.get_selected()
91 labExplain.set_content(explmodes[sel[0]])
92 lstTest.config(selectmode=modes[sel[0]])
95winMain = Ntk.Main(200, 150, 600, 450,
"NtkListbox widget sample")
98hfr1 = Ntk.HorFrame(winMain, 0, 0, FILL, FILL)
99rfr1 = Ntk.RowFrame(hfr1, 0, 0,
"50%", FILL)
100vfr2 = Ntk.VerFrame(hfr1, PACK, 0, FILL, FILL)
103labTest = Ntk.Label(rfr1, 0, 0, FILL, FILL, pad=(10, 10, 10, 5),
104 content=
"Try to select items")
105labTest.config(bcolor=
"light green", fcolor=
"blue", relief=SOLID,
106 borderwidth=1, anchor=CENTER)
109lstTest = Ntk.Listbox(rfr1, 0, 0, FILL, FILL, pad=(10, 5, 10, 40),
110 command=lbox_changed)
111lstTest.config(bcolor=
"blue", fcolor=
"yellow", sfcolor=
"maroon", sbcolor=
"light blue",
112 relief=RIDGE, font=(
"TkDefaultFont", 14))
115labSel = Ntk.Label(rfr1, 0, 0, FILL, FILL, pad=(10, 5))
116labSel.config(bcolor=
"light green", fcolor=
"blue", relief=SOLID,
123butAdd = Ntk.Button(rfr1,
"15%", 0,
"35%", FILL, pad=(5,5, 5, 10),
124 content=
"Add item", command=add_item)
125butDel = Ntk.Button(rfr1, PACK, PACK,
"35%", FILL, pad=(5, 5, 5, 10),
126 content=
"Del item", command =del_item)
129labMode = Ntk.Label(vfr2, 0, 0, FILL, 40, pad=(10, 10, 10, 5),
130 content=
"Listbox Mode")
131labMode.config(bcolor=
"light green", fcolor=
"blue", relief=SOLID, borderwidth=1,
133lstMode = Ntk.Listbox(vfr2, 0, PACK, FILL, 120, pad=(10, 5),
134 command=mode_changed, items=modes)
135lstMode.config(bcolor=
"cyan", fcolor=
"brown", font=(
"TkDefaultFont", 14), relief=RIDGE)
136labExplain=Ntk.Label(vfr2, 0, PACK, FILL, FILL, pad=(10, 10),
137 content=explmodes[0])
138labExplain.config(anchor=NW)
Definition: constants.py:1