最终的运行效果(程序见序号3):
# ------------------------------------------------分割线-------------------------------------------------
# ------------------------------------------------分割线-------------------------------------------------
# ------------------------------------------------分割线-------------------------------------------------
# ------------------------------------------------分割线-------------------------------------------------
'''
# ------------------------------------------------------------
# # 1、Checkbutton设定勾选选项
# # #
# ------------------------------------------------------------
'''
# import tkinter as tk
#
# window = tk.Tk()
# window.title("class7_Checkbutton 勾选项 ")
# window.geometry('300x400')
#
# c1 = tk.Checkbutton(window, text='C')
# c1.pack()
#
# c2 = tk.Checkbutton(window, text='C++')
# c2.pack()
#
# c3 = tk.Checkbutton(window, text='python')
# c3.pack()
#
# tk.mainloop()
#
# # ------------------------------------------------分割线-------------------------------------------------
'''
# ------------------------------------------------------------
# # 2、Checkbutton设定勾选选项 + 标签
# # #
# ------------------------------------------------------------
'''
# import tkinter as tk
#
# window = tk.Tk()
# window.title("class7_Checkbutton 勾选项 ")
# window.geometry('300x400')
#
# # 标签
# l1 = tk.Label(window, text='empty', width=40, bg='yellow')
# l1.pack()
#
# # 勾选项
# c1 = tk.Checkbutton(window, text='C')
# c1.pack()
#
# c2 = tk.Checkbutton(window, text='C++')
# c2.pack()
#
# c3 = tk.Checkbutton(window, text='python')
# c3.pack()
#
# tk.mainloop()
# # ------------------------------------------------分割线-------------------------------------------------
'''
# ------------------------------------------------------------
# # 3、Checkbutton设定勾选选项 + 标签(显示选项内容)
# # #
# ------------------------------------------------------------
'''
# import tkinter as tk
#
# def print_selection():
# global var1, var2, var3, l1
# if( (var1.get()==True) and (var2.get()==False) and (var3.get()==False) ):
# l1.config(text='C')
# elif(var1.get()==False and var2.get()==True and var3.get()==False):
# l1.config(text='C++')
# elif( (var1.get()==False) and (var2.get()==False) and (var3.get()==True) ):
# l1.config(text='python')
# else:
# l1.config(text='Not easy for me')
#
#
# window = tk.Tk()
# window.title("class7_Checkbutton 勾选项 ")
# window.geometry('300x400')
#
# # 标签
# l1 = tk.Label(window, text='empty', width=40, bg='yellow')
# l1.pack()
#
# var1 = tk.IntVar()
# var2 = tk.IntVar()
# var3 = tk.IntVar()
# # 勾选项
# # onvalue 打勾的值是 True
# # False 不打勾的值是 False
# # 将对应的值赋值给 variable
# c1 = tk.Checkbutton(window, text='C', onvalue=True, offvalue=False, variable=var1, command=print_selection)
# c1.pack()
#
# c2 = tk.Checkbutton(window, text='C++', onvalue=True, offvalue=False, variable=var2, command=print_selection)
# c2.pack()
#
# c3 = tk.Checkbutton(window, text='python', onvalue=True, offvalue=False, variable=var3, command=print_selection)
# c3.pack()
#
# tk.mainloop()
#
最终的运行效果(程序见序号3):