25def change_label_text(ev):
26 """This callback recognizes which widget called it,
27 and updates the upper label content accordingly.
"""
29 s =
"Pink button variable value: " + chk1Var.get()
30 elif ev.widget == chk2:
31 s =
"Orange button variable value: " + str(chk2Var.get())
33 s =
"Option " + str(optVar.get()) +
" selected"
34 labSample.set_content(s)
38winMain = Ntk.Main(200, 150, 600, 400,
"Radio and Check Buttons")
39winMain.config(bcolor=
"#FFFFA0")
40winMain.config_children(
"all", relief=
"groove")
43rfr1 = Ntk.RowFrame(winMain, 0, 0,
"fill",
"fill")
47labSample = Ntk.Label(rfr1, 0, 0,
"fill",
"fill", pad=10)
51chk1Var = Ntk.StringVar()
52chk1 = Ntk.Checkbutton(rfr1, 0, 0,
"40%",
"fill", pad=(10, 5, 5, 5),
53 content=
"This button controls a StrVar, which can get values: 'Value: on' and 'Value: off",
54 variable=(chk1Var,
"Value: on",
"Value: off"), command=change_label_text)
55chk1.config(bcolor=
"pink", abcolor=
"pink")
58labChk1 = Ntk.Label(rfr1,
"pack", 0,
"fill",
"fill", pad=(5, 5, 10, 5), content=chk1Var)
64chk2 = Ntk.Checkbutton(rfr1, 0, 0,
"40%",
"fill", pad=(10, 5, 5, 5),
65 content=
"This button controls an IntVar, which can get values: 0 and 1",
66 variable=chk2Var, command=change_label_text)
67chk2.config(bcolor=
"orange", abcolor=
"orange")
70labChk2 = Ntk.Label(rfr1,
"pack", 0 ,
"fill",
"fill", pad=(5, 5, 10, 5), content=chk2Var)
74frm3 = Ntk.VerFrame(rfr1, 10, 10, -10,
"fill")
75frm3.config(relief=
"groove")
76frm3.config_children(
"all", relief=
"flat")
81rad1 = Ntk.Radiobutton(frm3, 0,
"pack",
"fill",
"33%", content=
"Option 1",
82 variable=(optVar, 1), command=change_label_text)
83rad2 = Ntk.Radiobutton(frm3, 0,
"pack",
"fill",
"33%", content=
"Option 2",
84 variable=(optVar, 2), command=change_label_text)
85rad3 = Ntk.Radiobutton(frm3, 0,
"pack",
"fill",
"33%", content=
"Option 3",
86 variable=(optVar, 3), command=change_label_text)
90labSample.set_content(
"")