26CITIES = (
"Bari",
"Bologna",
"Firenze",
"Milano",
"Napoli",
"Palermo",
27 "Roma",
"Torino",
"Venezia")
30def change_label(event):
31 """This is called when you select a city in the upper combo;
32 it prints the selected city on the helper label."""
33 sel = cmbCities.get_content()
34 labHelp.set_content("You selected: " + sel)
38 """This is called by ButDel; it deletes the selected city
39 from the upper combo
and adds it to the lower.
"""
41 sel = cmbCities.get_content()
44 ind = cmbCities.index(sel)
49 if cmbCities.get_menu().size() > 0:
52 cmbCities.set_content(cmbCities.get_item(ind))
53 labHelp.set_content(
"You deleted {} (but it is now in the lower combobox".format(sel))
56 labHelp.set_content(
"Empty menu")
60 """This is called by ButIns; it deletes a city in the lower combo
61 and adds it to the upper.
"""
62 sel = cmbIns.get_content()
65 ind = cmbIns.index(sel)
68 labHelp.set_content(
"You newly added {} to the upper combobox".format(sel))
69 if cmbIns.get_menu().size() > 0:
70 cmbIns.set_content(cmbIns.get_item(ind))
74def reset_combo(event):
75 """This callback resets the contents of the two combos"""
80 cmbCities.set_content(CITIES[0])
83 labHelp.set_content(
"You reset the combos")
86winMain = Ntk.Main(200, 150, 400, 300,
"Combobox sample")
88winMain.config_children(ALL, font=(
"Arial", 16))
89winMain.config_children((Ntk.Button, Ntk.Combobox), bcolor=
"#D0D080", abcolor=
"#E0E090")
91cmbCities = Ntk.Combobox(winMain, 0, 0, FILL, 70, pad=(10, 20, 10, 10),
92 items=CITIES, command=change_label)
94labHelp = Ntk.Label(winMain, 0, PACK, FILL, 90, pad=10,
95 content=
"Initially selected: " + CITIES[0])
96labHelp.config(bcolor=
"#B0D0F0", relief=RIDGE, anchor=CENTER)
98rfr1 = Ntk.RowFrame(winMain, 0, PACK, FILL, FILL)
101butDel = Ntk.Button(rfr1, 0, 0,
"50%", FILL, pad=(10, 10, 10, 5),
102 content=
"Delete selected", command=delete_sel)
104butRes = Ntk.Button(rfr1, PACK, 0, FILL, FILL, pad=(10, 10, 10, 5),
105 content=
"Reset", command=reset_combo)
108butIns = Ntk.Button(rfr1, 0, 0,
"50%", FILL, pad=(10, 5, 10, 10),
109 content=
"Insert selected", command=insert_sel)
112cmbIns = Ntk.Combobox(rfr1, PACK, 0, FILL, FILL, pad=(10, 5, 10, 10))
114cmbCities.bind(
"<<ChangedVar>>",
115 lambda ev: butDel.activate()
if len(ev.widget.get_content())
else butDel.deactivate())
116cmbIns.bind(
"<<ChangedVar>>",
117 lambda ev: butIns.activate()
if len(ev.widget.get_content())
else butIns.deactivate())
Definition: constants.py:1