1 #tkinter check box action2 3 ImportTkinter as TK4 5Root =tk. Tk ()6Root.title ('Questionnaire Survey')7Root.geometry ('220x80')#Set Window Size8 9Flag_1 =FalseTenFlag_2 =False OneFlag_3 =False AList_content = ['your hobbies are:'] -Hobby_list = ['Swimming','singing','Travel'] - the - defclick_1 (): - Globalflag_1 -Flag_1 = notflag_1 + ifflag_1: - list_content.append (hobby_list[0]) + Else: A List_content.remove (hobby_list[0]) at #print (' Your hobby is: ', list_content) -lab_msg['text'] =list_content - - - defclick_2 (): - Globalflag_2 inFlag_2 = notflag_2 - ifflag_2: toList_content.append (hobby_list[1]) + Else: -List_content.remove (hobby_list[1]) the #print (' Your hobby is: ', list_content) *lab_msg['text'] =list_content $ Panax Notoginseng - defclick_3 (): the GlobalFlag_3 +Flag_3 = notFlag_3 A ifFlag_3: theList_content.append (hobby_list[2]) + Else: -List_content.remove (hobby_list[2]) $ #print (' Your hobby is: ', list_content) $lab_msg['text'] =list_content - - the " "form Controls" " - #Title DisplayWuyiLab = Tk. Label (Root, text='Please choose your hobby:') theLab.grid (row=0, columnspan=3, sticky=tk. W) - Wu #Multi-Select box -frm =tk. Frame (Root) AboutCk1 = Tk. Checkbutton (frm, text='Swimming', command=click_1) $Ck2 = Tk. Checkbutton (frm, text='singing', command=click_2) -Ck3 = Tk. Checkbutton (frm, text='Travel', command=click_3) -Ck1.grid (row=0) -Ck2.grid (row=0, Column=1) ACk3.grid (row=0, column=2) +Frm.grid (row=1) the -Lab_msg = Tk. Label (Root, text="') $Lab_msg.grid (row=2, columnspan=3, sticky=tk. W) the theRoot.mainloop ()
:
Python's tkinter Use-check box action