sairate 7df250638d chore: 添加项目基础结构和示例代码
- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
2025-07-05 09:36:00 +08:00

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 同盟集结
import tkinter as tk # 导入tkinter库
# 检验答案,返回结果
def check_answer():
answer = var.get()
if answer == "HTML":
result_label.config(text="恭喜你获得考验资格,你敢接受挑战吗?")
else:
result_label.config(text="很遗憾,下次有缘再见")
# 创建主窗口
root = tk.Tk() # 创建主窗口对象起名为root
root.title("同盟集结") # 配置窗口标题
root.geometry('400x200+400+400') # 设置窗口大小
# 出题
question_label = tk.Label(root, text="以下哪个选项不是编程语言?")
question_label.pack()
# 设置单选按钮
var = tk.StringVar()
option_1 = tk.Radiobutton(root, text="Python", variable=var, value="Python")
option_2 = tk.Radiobutton(root, text="HTML", variable=var, value="HTML")
option_1.pack()
option_2.pack()
# 创建提交按钮
tijiao_button = tk.Button(root, text="提交答案", command=check_answer)
tijiao_button.pack()
# 创建结果标签
result_label = tk.Label(root, text="")
result_label.pack()
# 运行主循环,等待用户交互
root.mainloop()