sairate 2cd753d3d9 feat(第7讲 字母卡牌): 实现记忆游戏并添加开始界面
- 新增 jiyi.py 文件,实现字母翻牌记忆游戏功能
- 添加 youxijiemian.py 文件,创建游戏开始界面
- 使用 turtle 和 tkinter 模块分别实现游戏和界面
- 支持选择不同难度的游戏模式
2025-06-29 09:06:19 +08:00

41 lines
1.3 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.

# 导入所需要的库
from tkinter import *
import random
# 创建主窗口
root = Tk()
root.geometry('500x150+300+500')
root.title('点名系统')
bg_image = PhotoImage(file = '点名.png')
bg_label = Label(root, image = bg_image)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
# 设置全局变量
var = StringVar() # 这个变量用来显示在标签上的名字
names = ['小明', '红红', '粘豆包', '牛牛'] # 这个列表存储学生的名字
flag = False # 这个标志用来表示是否正在进行点名
# 定义一个函数,用来进行点名
def roll():
if flag: # 如果正在进行点名,那么显示一个随机的名字
var.set(random.choice(names))
root.after(10, roll) # 在10毫秒后再次调用这个函数
# 定义一个函数,用来切换点名状态
def check():
global flag # 声明我们要使用的是全局变量,而不是创建一个新的局部变量
if flag: # 如果正在进行点名,那么停止点名
flag = False
else: # 否则,开始点名
flag = True
roll()
# 创建并配置标签和按钮
Label(root, textvariable=var, font=('楷体', 50)).pack()
Button(root, text="开始/停止点名", command=check).pack()
# 启动事件循环
root.mainloop()