摘要:"text": "宝镜新磨照,云间月正明\n广寒宫里有,丹桂一枝荣",
尝试用deepseek无基础编程,直接让它帮我生成一段可以运行的用来许愿的小程序代码:
import tkinter as tk
from tkinter import messagebox
import random
import datetime
import os
# 签文数据
lottery_data = [
{
"type": "大吉",
"text": "宝镜新磨照,云间月正明\n广寒宫里有,丹桂一枝荣",
"text": "舟离古渡月离云\n人出潼关好问津\n且向前行去求往\n何须疑虑两三声",
"text": "白虎当头坐命宫\n名利财帛总成空\n病逢仙丹效少奏\n趋吉避凶诚为重",
"interpretation": "谨慎行事安守本分\n修身养性以待天时"
}
]
# 保存愿望的文件
WISH_FILE = "wishs.txt"
class WishApp:
def __init__(self, root):
self.root = root
self.root.title("许愿抽签小游戏")
self.root.geometry("400x300")
self.create_widgets
def create_widgets(self):
# 标题
title_label = tk.Label(self.root, text="心愿祈愿社", font=("楷体", 20, "bold"))
title_label.pack(pady=10)
# 许愿按钮
wish_button = tk.Button(self.root, text="许下心愿", command=self.make_wish, font=("宋体", 14))
wish_button.pack(pady=10)
# 抽签按钮
lottery_button = tk.Button(self.root, text="神明抽签", command=self.draw_lottery, font=("宋体", 14))
lottery_button.pack(pady=10)
# 查看愿录按钮
view_button = tk.Button(self.root, text="查看愿录", command=self.view_wishes, font=("宋体", 14))
view_button.pack(pady=10)
# 退出按钮
exit_button = tk.Button(self.root, text="退出程序", command=self.root.quit, font=("宋体", 14))
exit_button.pack(pady=10)
def make_wish(self):
wish = tk.simpledialog.askstring("许愿", "请写下你的心愿:")
if wish:
timestamp = datetime.datetime.now.strftime("%Y-%m-%d %H:%M:%S")
with open(WISH_FILE, "a", encoding="utf-8") as f:
f.write(f"[{timestamp}] {wish}\n")
messagebox.showinfo("提示", "心愿已存入愿盒✨")
def draw_lot
用python软件尝试运行了下,发现无法运行,怀疑是def draw_lot
没有定义,然后尝试让deepseek自己修正代码。
修正后的完整代码:
import tkinter as tk
from tkinter import messagebox, simpledialog # 添加simpledialog导入
import random
import datetime
import os
# 签文数据
lottery_data = [
{
"type": "大吉",
"text": "宝镜新磨照,云间月正明\n广寒宫里有,丹桂一枝荣",
"interpretation": "所谋皆遂所求皆得\n出行大吉功名必就"
},
{
"type": "中吉",
"text": "舟离古渡月离云\n人出潼关好问津\n且向前行去求往\n何须疑虑两三声",
"interpretation": "出入皆宜前程亨通\n心无挂碍万事可成"
},
{
"type": "小吉",
"text": "天上仙花难问种\n人间尘事几多更\n前程已注公私簿\n罚赏分明浊与清",
"interpretation": "顺其自然莫强求\n但行好事问心无愧"
},
{
"type": "凶",
"text": "白虎当头坐命宫\n名利财帛总成空\n病逢仙丹效少奏\n趋吉避凶诚为重",
"interpretation": "谨慎行事安守本分\n修身养性以待天时"
}
]
# 保存愿望的文件
WISH_FILE = "wishs.txt"
class WishApp:
def __init__(self, root):
self.root = root
self.root.title("许愿抽签小游戏")
self.root.geometry("400x300")
self.create_widgets
def create_widgets(self):
# 标题
title_label = tk.Label(self.root, text="心愿祈愿社", font=("楷体", 20, "bold"))
title_label.pack(pady=10)
# 许愿按钮
wish_button = tk.Button(self.root, text="许下心愿", command=self.make_wish, font=("宋体", 14))
wish_button.pack(pady=10)
# 抽签按钮
lottery_button = tk.Button(self.root, text="神明抽签", command=self.draw_lottery, font=("宋体", 14))
lottery_button.pack(pady=10)
# 查看愿录按钮
view_button = tk.Button(self.root, text="查看愿录", command=self.view_wishes, font=("宋体", 14))
view_button.pack(pady=10)
# 退出按钮
exit_button = tk.Button(self.root, text="退出程序", command=self.root.quit, font=("宋体", 14))
exit_button.pack(pady=10)
def make_wish(self):
wish = simpledialog.askstring("许愿", "请写下你的心愿:") # 修正为直接使用simpledialog
if wish:
timestamp = datetime.datetime.now.strftime("%Y-%m-%d %H:%M:%S")
with open(WISH_FILE, "a", encoding="utf-8") as f:
f.write(f"[{timestamp}] {wish}\n")
重新尝试,顺利运行,太神奇了。
来源:超级首负