吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 621|回复: 32
收起左侧

[求助] deepseek编画板程序遇到问题?

[复制链接]
public123 发表于 2025-3-23 09:38
本帖最后由 public123 于 2025-3-23 09:40 编辑

[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import tkinter as tk
from tkinter.colorchooser import askcolor
from PIL import ImageGrab, Image, ImageDraw
 
class PaintApp:
    def __init__(self, root):
        self.root = root
        self.root.title("画板程序")
 
        # 设置画布
        self.canvas = tk.Canvas(root, bg="white", width=800, height=600)
        self.canvas.pack(fill=tk.BOTH, expand=True)
 
        # 设置画笔
        self.brush_color = "black"
        self.brush_size = 2
 
        # 设置按钮框架
        self.button_frame = tk.Frame(root)
        self.button_frame.pack(side=tk.TOP, fill=tk.X)
 
        # 颜色选择按钮
        self.color_button = tk.Button(self.button_frame, text="选择颜色", command=self.choose_color)
        self.color_button.pack(side=tk.LEFT, padx=5, pady=5)
 
        # 画笔大小调整按钮
        self.size_button = tk.Button(self.button_frame, text="画笔大小", command=self.choose_size)
        self.size_button.pack(side=tk.LEFT, padx=5, pady=5)
 
        # 保存按钮
        self.save_button = tk.Button(self.button_frame, text="保存", command=self.save_canvas)
        self.save_button.pack(side=tk.LEFT, padx=5, pady=5)
 
        # 清空按钮
        self.clear_button = tk.Button(self.button_frame, text="清空", command=self.clear_canvas)
        self.clear_button.pack(side=tk.LEFT, padx=5, pady=5)
 
        # 绑定鼠标事件
        self.canvas.bind("<B1-Motion>", self.paint)
        self.canvas.bind("<ButtonRelease-1>", self.reset)
 
        # 初始化画笔位置
        self.last_x = None
        self.last_y = None
 
    def choose_color(self):
        color = askcolor(color=self.brush_color)[1]
        if color:
            self.brush_color = color
 
    def choose_size(self):
        size = tk.simpledialog.askinteger("画笔大小", "输入画笔大小", initialvalue=self.brush_size)
        if size:
            self.brush_size = size
 
    def paint(self, event):
        if self.last_x and self.last_y:
            self.canvas.create_line(self.last_x, self.last_y, event.x, event.y,
                                    width=self.brush_size, fill=self.brush_color,
                                    capstyle=tk.ROUND, smooth=tk.TRUE)
        self.last_x = event.x
        self.last_y = event.y
 
    def reset(self, event):
        self.last_x = None
        self.last_y = None
 
    def clear_canvas(self):
        self.canvas.delete("all")
 
    def save_canvas(self):
        # 获取画布区域
        x = self.root.winfo_rootx() + self.canvas.winfo_x()
        y = self.root.winfo_rooty() + self.canvas.winfo_y()
        x1 = x + self.canvas.winfo_width()
        y1 = y + self.canvas.winfo_height()
 
        # 截取画布区域
        image = ImageGrab.grab(bbox=(x, y, x1, y1))
        image.save("canvas_image.png")
        tk.messagebox.showinfo("保存成功", "画布已保存为 canvas_image.png")
 
if __name__ == "__main__":
    root = tk.Tk()
    app = PaintApp(root)
    root.mainloop()




哪位大佬可以帮忙看一下用deepseek编的画板程序哪里有问题?

免费评分

参与人数 1热心值 +1 收起 理由
wyff123 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

flybird2007 发表于 2025-3-23 10:41
遇到的问题是什么你要说一下啊

免费评分

参与人数 1热心值 +1 收起 理由
public123 + 1 我很赞同!

查看全部评分

NetStar8977 发表于 2025-3-23 10:44
ccxk 发表于 2025-3-23 10:49
Dengghhui 发表于 2025-3-23 10:49
期待学习中~~
 楼主| public123 发表于 2025-3-23 10:53
flybird2007 发表于 2025-3-23 10:41
遇到的问题是什么你要说一下啊

等我开电脑后截图给你吧
asi7 发表于 2025-3-23 11:00
学习一下!
愚无尽 发表于 2025-3-23 11:06
你继续问ds不就完了
gwgdaemon 发表于 2025-3-23 11:11
我运行了一下,没有问题啊
mmh1 发表于 2025-3-23 12:12
知道问题还好,就是怕没有错误,运行起来没结果
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-3-30 20:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表