源代码:
# 创建主窗口
import tkinter as tk
window = tk.Tk()
window.title('勾选项')
window.geometry('300x200')
# 创建标签,用于显示勾选中的内容
l = tk.Label(window, bg='green', width=25, height=2, text='empty')
l.pack()
var1 = tk.IntVar() # 用来储存下面勾选项1中返回的0或1
var2 = tk.IntVar() # 用来储存下面勾选项2中返回的0或1
# 在标签中打印内容
def print_selection():
if (var1.get()==1) and (var2.get()==0): # 只勾选选项1
l.config(text='未来是人工智能的时代')
elif (var1.get()==1) and (var2.get()==1): # 勾选选项1和2
l.config(text='未来是人工智能和区块链的时代')
elif (var1.get()==0) and (var2.get()==0): # 选项1和2都不勾选
l.config(text='未来是不确定的时代')
else: