Various forms of menus: menubar, combobox, popup.
28 labText.set_content(
"You have chosen '" + event.value +
"' from the menu in the menubar")
30def hitmenubutton(event):
31 labText.set_content(
"Edit is " + editon.get())
34 labText.config(bcolor=event.value)
37 labText.set_content(
"You have chosen '" + event.value +
"' from the popup menu")
40 labText.set_content(
"You have chosen '" + event.value +
"' from the combobox")
44winMain = Ntk.Main(200, 180, 640, 480,
"Menu example")
45winMain.config_children(Ntk.Label, relief=SOLID, borderwidth=1)
47menuBar = Ntk.Menu(winMain)
49menuFile = Ntk.Menu(menuBar,
"File")
50menuFile.add_command(label=
"Open", command=(hitmenu,
"Open"))
51menuFile.add_command(label=
"Save", command=(hitmenu,
"Save"))
52menuFile.add_command(label=
"Save as ...", command=(hitmenu,
"Save as ..."))
53menuFile.add_separator()
54menuFile.add_command(label=
"Quit", command=
lambda event: winMain.destroy())
56menuEdit = Ntk.Menu(menuBar,
"Edit")
57menuEdit.add_checkbutton(label=
"Edit on", command=hitmenubutton)
60editon = Ntk.StringVar()
61menuEdit.entry_set_variable(
"Edit on", variable=editon, offvalue=
"off", onvalue=
"on")
63menuColors = Ntk.Menu(menuBar,
"Colors")
64menuColors.add_command(label=
"Change to green", command=(hitcolors,
"light green"))
65menuColors.add_command(label=
"Change to pink", command=(hitcolors,
"pink"))
66menuColors.add_command(label=
"Change to blue", command=(hitcolors,
"light blue"))
68menuColors.entry_config(0, bcolor=
"light green")
69menuColors.entry_config(1, bcolor=
"pink")
70menuColors.entry_config(2, bcolor=
"light blue")
73menuPopup = Ntk.Menu(winMain, popup=
True)
74menuPopup.add_command(label=
"Cut", command=(hitpopup,
"Cut"))
75menuPopup.add_command(label=
"Copy", command=(hitpopup,
"Copy"))
76menuPopup.add_command(label=
"Paste", command=(hitpopup,
"Paste"))
79labPopup=Ntk.Label(winMain, 0,
"10%",
"fill", 100, pad=(15, 10), content=
"Double click to open a popup", )
80labPopup.bind(
"<Double-Button-1>",
lambda event: menuPopup.post(event.x_root, event.y_root))
81labPopup.config(bcolor=
"orange", anchor=CENTER, font=(
"Arial", 12,
"bold"))
84cmbmenu = [
"Option " + str(i + 1)
for i
in range(100)]
85cmbSample = Ntk.Combobox(winMain, CENTER, PACK,
"80%", 50, pad=(0, 5), items=cmbmenu, command=hitcombo)
86cmbSample.config(fcolor=
"dark blue", afcolor=
"blue", font=(
"Arial", 12,
"bold"))
89labText = Ntk.Label(winMain, PACK, PACK, FILL, FILL, pad=(15, 10))
90labText.config(bcolor=
"light green", fcolor=
"dark green", font=(
"Arial", 16), anchor=CENTER)
Definition: constants.py:1