commit 0843bb90dc7c9178997d64c36dcc2ffc97eaf5e1 Author: sairate Date: Fri Jun 6 16:56:19 2025 +0800 feat: 创建测测你的星座吧项目 - 添加主程序文件 main.py,实现星座查询功能 - 创建 .idea 目录及相关配置文件,配置项目环境 - 添加 README.md 文件,说明项目依赖安装方法 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/Constellationquery.iml b/.idea/Constellationquery.iml new file mode 100644 index 0000000..fae893c --- /dev/null +++ b/.idea/Constellationquery.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..25bde2c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..ef4c87e --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..16eed9c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dd91716 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdd81f2 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +```bash +pip install -i https://mirrors.aliyun.com/pypi/simple/ pillow +``` \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..d8587f9 --- /dev/null +++ b/main.py @@ -0,0 +1,111 @@ +import tkinter as tk +from PIL import Image, ImageTk +from tkinter import messagebox + + +# 预置内容,请勿改动 +def check(month, day): # 判断星座的函数 + if (month == 1 and day >= 20) or (month == 2 and day <= 18): + return "水瓶座♒" + elif (month == 2 and day >= 19) or (month == 3 and day <= 20): + return "双鱼座♓" + elif (month == 3 and day >= 21) or (month == 4 and day <= 19): + return "白羊座♈" + elif (month == 4 and day >= 20) or (month == 5 and day <= 20): + return "金牛座♉" + elif (month == 5 and day >= 21) or (month == 6 and day <= 21): + return "双子座♊" + elif (month == 6 and day >= 22) or (month == 7 and day <= 22): + return "巨蟹座♋" + elif (month == 7 and day >= 23) or (month == 8 and day <= 22): + return "狮子座♌" + elif (month == 8 and day >= 23) or (month == 9 and day <= 22): + return "处女座♍" + elif (month == 9 and day >= 23) or (month == 10 and day <= 23): + return "天秤座♎" + elif (month == 10 and day >= 24) or (month == 11 and day <= 22): + return "天蝎座♏" + elif (month == 11 and day >= 23) or (month == 12 and day <= 21): + return "射手座♐" + elif (month == 12 and day >= 22) or (month == 1 and day <= 19): + return "摩羯座♑" + + +# 创建Tkinter窗口 +root = tk.Tk() +root.geometry('320x360') +root.title("测测你的星座吧") + +# 创建一个标签用于显示gif动画 +label_bg = tk.Label(root) +label_bg.place(x=0, y=0, relwidth=1, relheight=1) # 将标签放在窗口顶部并充斥整个窗口 + +# 加载gif图片并将每一帧存储在frames列表中 +image = Image.open('星图.gif') # 打开gif图片文件 +frames = [] # 用于存储gif的所有帧 +try: + while True: + frames.append(ImageTk.PhotoImage(image)) # 将每一帧添加到frames列表中 + image.seek(len(frames)) # 跳转到gif的下一帧 +except EOFError: + pass # 当到达gif结束时,跳出循环 + + +# 用于更新gif动画帧的函数 +def upd(idx): + frame = frames[idx] # 获取当前帧 + label_bg.configure(image=frame) # 更新标签中显示的帧 + idx = (idx + 1) % len(frames) # 计算下一帧的索引 + root.after(100, upd, idx) # 100毫秒后调用自己继续更新帧 + + +upd(0) # 开始播放gif动画 + +# 创建标签和文本框 +label_year = tk.Label(root, text="出生年:") +label_year.grid(row=0, column=0, padx=(60, 10), pady=(140, 10)) + +entry_year = tk.Entry(root) +entry_year.grid(row=0, column=1, pady=(140, 10)) + +label_month = tk.Label(root, text="出生月:") +label_month.grid(row=1, column=0, padx=(60, 10), pady=10) + +entry_month = tk.Entry(root) +entry_month.grid(row=1, column=1, pady=10) + +label_day = tk.Label(root, text="出生日:") +label_day.grid(row=2, column=0, padx=(60, 10), pady=10) + +entry_day = tk.Entry(root) +entry_day.grid(row=2, column=1, pady=10) + + +# 按钮点击处理函数 +# 点击提交按钮时调用,它获取用户输入的出生年月日,验证输入有效性,并显示对应的星座信息 +def click(): + year = entry_year.get() # 获取用户输入的出生年份 + month = entry_month.get() # 获取用户输入的出生月份 + day = entry_day.get() # 获取用户输入的出生日 + + # 检查用户输入的年、月、日是否为有效的数字 + if not year.isdigit() or not month.isdigit() or not day.isdigit(): + messagebox.showerror("输入错误", "请输入有效的日期") + + month = int(month) # 将月份转换为整数 + day = int(day) # 将日期转换为整数 + + # 检查日期是否在有效范围内 + if month < 1 or month > 12 or day < 1 or day > 31: + messagebox.showerror("输入错误", "请输入有效的日期") + + result = check(month, day) # 调用check函数获取星座信息 + messagebox.showinfo("星座", f"你的星座是:{result}") # 显示用户的星座信息 + + +# 创建提交按钮 +btn = tk.Button(root, text="提交", command=click) +btn.grid(row=3, columnspan=2, padx=(80, 10), pady=10) + +# 运行Tkinter主循环 +root.mainloop() diff --git a/星图.gif b/星图.gif new file mode 100644 index 0000000..a888f0f Binary files /dev/null and b/星图.gif differ