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

39 lines
1.2 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.

# 编程前,运行【安装第三方库.py】文件安装本课用到的第三方库
import tkinter
from PIL import Image, ImageTk
from tkinter import filedialog
import os
from amzqr import amzqr
w = tkinter.Tk()
w.geometry("400x400")
w.resizable(0,0)
bg_image = Image.open("qrcode_bg.png")
bg_image = ImageTk.PhotoImage(bg_image)
bg_label = tkinter.Label(w, image=bg_image)
bg_label.pack()
t1 = tkinter.Text(w, font=("微软雅黑", 12),width=30,height=5)
t1.place(x=80, y=100)
t2 = tkinter.Text(w, font=("微软雅黑", 12),width=23,height=1)
t2.place(x=80, y=250)
def get_pic():
pic_path = filedialog.askopenfilename()
t2.delete("1.0", "end")
t2.insert("1.0", pic_path)
btn1 = tkinter.Button(w, text="浏览", font=("微软雅黑", 12), command=get_pic)
btn1.place(x=312, y=250, height=25)
def qr():
words = t1.get("1.0","end")
words = "".join(words.split('\n'))
picture = t2.get("1.0", "end")[:-1]
version, level, qr_name = amzqr.run(words=words, picture=picture, colorized=True)
os.system(qr_name)
btn2 = tkinter.Button(w, text="生成二维码", font=("微软雅黑", 15), command=qr)
btn2.place(x=80, y=300, width=250)
w.mainloop()