feat: 创建测测你的星座吧项目

- 添加主程序文件 main.py,实现星座查询功能
- 创建 .idea 目录及相关配置文件,配置项目环境
- 添加 README.md 文件,说明项目依赖安装方法
This commit is contained in:
sairate 2025-06-06 16:56:19 +08:00
commit 0843bb90dc
10 changed files with 174 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

10
.idea/Constellationquery.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (Constellationquery)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,14 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="numpy" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

12
.idea/material_theme_project_new.xml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="21c1c7ee:193388d497c:-7ff9" />
</MTProjectMetadataState>
</option>
</component>
</project>

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10 (Constellationquery)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Constellationquery)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Constellationquery.iml" filepath="$PROJECT_DIR$/.idea/Constellationquery.iml" />
</modules>
</component>
</project>

3
README.md Normal file
View File

@ -0,0 +1,3 @@
```bash
pip install -i https://mirrors.aliyun.com/pypi/simple/ pillow
```

111
main.py Normal file
View File

@ -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()

BIN
星图.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB