会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132485个问题
WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 29821楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 29822楼

from tkinter.filedialog  import *
from tkinter.colorchooser import *
win_width=900
win_height=450


class Application(Frame):
    def __init__(self,master=None,bgcolor="#000000"):
        super().__init__(master)
        self.master = master
        self.bgcolor=bgcolor
        self.x = 0
        self.y = 0
        self.fgcolor = "#ff0000"
        self.pack()
        self.createWidget()

    def createWidget(self):
        self.drawpad = Canvas(root,width=win_width,height=win_height*0.9,bg=self.bgcolor)
        self.drawpad.pack()

        btn_start = Button(root,text="开始",name="start")
        btn_start.pack(side="left",padx="10")

        btn_pen = Button(root, text="画笔", name="pen")
        btn_pen.pack(side="left", padx="10")

        btn_line = Button(root,text="直线",name="line")
        btn_line.pack(side="left",padx="10")

        btn_circle = Button(root,text="圆",name="circle")
        btn_circle.pack(side="left",padx="10")

        btn_eraser = Button(root,text="橡皮擦",name="eraser")
        btn_eraser.pack(side="left",padx="10")

        btn_rect = Button(root,text="矩形",name="rect")
        btn_rect.pack(side="left",padx="10")

        btn_clear = Button(root,text="清屏",name="clear")
        btn_clear.pack(side="left",padx="10")

        btn_linearrow = Button(root, text="箭头线", name="linearrow")
        btn_linearrow.pack(side="left", padx="10")

        btn_color = Button(root,text="颜色",name="color")
        btn_color.pack(side="left",padx="10")

    def eventManager(self,event):
        name = event.widget.winfo_name()
        print(name)
        if name == "line":
            self.drawpad.bind("<B1-Motion>",self.myline)

    def myline(self,event):
        self.drawpad.create_line(self.x,self.y,event.x,event.y,fill=self.fgcolor)

if __name__ == '__main__':
    root = Tk()
    root.geometry(str(win_width)+"x"+str(win_height)+"+200+100")
    root.title("画图软件")
    app = Application(master=root)
    root.mainloop()

老师,这个运行下来不报错也没反应

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 29823楼
WEB前端全系列/第五阶段:前后端交互/PHP、数据库编程与设计 29824楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 29826楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 29827楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 29828楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 29829楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 29831楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 29832楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 29834楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 29835楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637