tkinter库在开发客户端软件中应用广泛。今天介绍使用tkinter库中的checkbutton控件创建复选框。直接用实例来演示它的用法。

# encoding=utf-8 
# Author:HaiFeng
# Date:2023.09.20
'''
多复选框应用
'''
# 引入第三方库
from tkinter import *

# 创建调用功能函数
def fuc1():
	if fVar.get():
		lb1.config(text='调取fuc1',bg='red')
	else:
		lb1.config(text='',bg='blue')
def fuc2():	
	if sVar.get():
		lb2.config(text='调取fuc2',bg='pink')
	else:
		lb2.config(text='',bg='blue')

# 创建显示窗体
root = Tk()
fVar = BooleanVar();sVar = BooleanVar();
root.geometry('139x177');
root.config(bg='lightyellow')
cbnt1 = Checkbutton(root,text='这是第一个复选按钮',variable=fVar,command=fuc1,bg='lightgreen');
cbnt1.place(x=0,y=6)
cbnt2 = Checkbutton(root,text='这是第二个复选按钮',variable=sVar,command=fuc2,bg='lightgreen');
cbnt2.place(x=0,y=36)
lb1 = Label(root,width=17,height=3,bg='blue');
lb1.place(x=6,y=66)
lb2 = Label(root,width=17,height=3,bg='blue');
lb2.place(x=6,y=116)
root.mainloop()

      程序运行结果

使用tkinter创建复选框_tkinter