chore: 添加项目基础结构和示例代码

- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
This commit is contained in:
sairate 2025-07-13 09:34:51 +08:00
parent fd2063095c
commit f5ae3e44c9
10 changed files with 128 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

View File

@ -0,0 +1,104 @@
import tkinter as tk
from PIL import Image, ImageTk
# 角色数据
characters = [
{
"name": "",
"quote": "",
"image": "images/凯.png"
},
{
"name": "李白",
"quote": "",
"image": "images/李白.png"
},
{
"name": "甄姬",
"quote": "",
"image": "images/甄姬.png"
},
{
"name": "百里守约",
"quote": "",
"image": "images/百里守约.png"
},
{
"name": "钟馗",
"quote": "",
"image": "images/钟馗.png"
}
]
# 图片等比缩放
def resize_image_keep_aspect(image, max_width=300, max_height=360):
ratio = min(max_width / image.width, max_height / image.height)
new_size = (int(image.width * ratio), int(image.height * ratio))
return image.resize(new_size, Image.Resampling.LANCZOS)
class RoleSwitcherApp:
def __init__(self, master):
self.master = master
self.master.title("角色切换器")
self.master.geometry("420x600") # 固定窗口大小
self.master.resizable(False, False) # 禁止缩放
self.index = 0
# 图片区域
self.image_label = tk.Label(master)
self.image_label.pack(pady=10)
# 名字
self.name_label = tk.Label(master, text="", font=("Arial", 16))
self.name_label.pack()
# 对话框区域
self.dialog_frame = tk.Frame(master, bg="#f0f0f0", padx=10, pady=10)
self.dialog_frame.pack(padx=10, pady=10, fill="x")
self.quote_label = tk.Label(
self.dialog_frame,
text="",
font=("微软雅黑", 13),
wraplength=400,
justify="left",
anchor="w"
)
self.quote_label.pack()
# 按钮区域
btn_frame = tk.Frame(master)
btn_frame.pack(pady=10)
tk.Button(btn_frame, text="← 上一个", command=self.prev_character).pack(side="left", padx=20)
tk.Button(btn_frame, text="下一个 →", command=self.next_character).pack(side="left", padx=20)
# 键盘控制
master.bind("<Left>", lambda event: self.prev_character())
master.bind("<Right>", lambda event: self.next_character())
self.update_display()
def update_display(self):
char = characters[self.index]
self.name_label.config(text=f"角色:{char['name']}")
image = Image.open(char["image"])
image = resize_image_keep_aspect(image)
self.tk_image = ImageTk.PhotoImage(image)
self.image_label.config(image=self.tk_image)
self.quote_label.config(text=f"{char['quote']}")
def next_character(self):
self.index = (self.index + 1) % len(characters)
self.update_display()
def prev_character(self):
self.index = (self.index - 1) % len(characters)
self.update_display()
if __name__ == "__main__":
root = tk.Tk()
app = RoleSwitcherApp(root)
root.mainloop()

View File

@ -0,0 +1,24 @@
import random
import os
import time
list=["特等奖","一等奖","二等奖","三等奖","安慰奖"]
for i in range(20):
print(random.choice(list))
time.sleep(0.1)
os.system('cls')
re=random.randint(1,100)
if re <= 1:
print("恭喜特等奖")
elif re <= 5:
print("恭喜一等奖")
elif re<= 10:
print("恭喜二等奖")
elif re <= 20:
print("恭喜三等奖")
else:
print("恭喜安慰奖")
os.system('pause')