会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132462个问题
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 31411楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Maven 31412楼

"""开发画图软件的菜单 """
#coding = "utf-8"

from tkinter import *
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.lastDraw = 0    #表示最后绘制的图形id
        self.startDrawFlag = False
        self.pack()
        self.createWidget()

    def createWidget(self):
        # 创建绘图区
        drawpad =Canvas(root,width=win_width,height=win_height*0.9,bg=self.bgcolor)
        drawpad.pack()

        # 创建按钮
        btn_srart = Button(root,text="开始",name="start")
        btn_srart.pack(side="left",padx="10")
        btn_pen = Button(root,text="画笔",name="pen")
        btn_pen.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_erasor = Button(root,text="橡皮擦",name="erasor")
        btn_erasor.pack(side="left",padx="10")
        btn_line = Button(root,text="直线",name="line")
        btn_line.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")

        # 事件处理
        btn_pen.bind_class("Button","<1>",self.eventManager)

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

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



if __name__ == '__main__':
    root = Tk()
    root.geometry(str(win_width)+"x"+str(win_height)+"+200+300")
    app = Application(master=root)
    root.title("画图软件")
    root.mainloop()
Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\software\Anaconda\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\admin\Desktop\code\深入与提高\画图软件开发1.py", line 54, in eventManager
    self.drawpadbind("<B1-Motion>",self.myline)
AttributeError: 'Application' object has no attribute 'drawpadbind'
line

这是什么原因导致的?

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 31415楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 31417楼
Python 全系列/第五阶段:数据库编程/mysql的使用 31419楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 31420楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 31421楼

分享:利用Scrapy框架爬取数据命令行保存成csv出现乱码的解决办法

https://blog.csdn.net/zhaomengszu/article/details/88658108

在创建项目的settings.py中,添加如下代码 
FEED_EXPORT_ENCODING = 'gb18030'

即可解决乱码问题。

但是这样做的一个副作用是:在用pycharm打开时可能出现乱码,这时根据提示reload in GBK即可

Python 全系列/第十五阶段:Python 爬虫开发/移动端爬虫开发- 31423楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Spring 31424楼

数组错误.png

老师,这段代码没有报错,为什么嵌套循环用不了,是不是定义类表述一个二维数组之后,实际上算是一维数组,不能算二维数组,所以嵌套循环用不了,以下是原码

package com.luzhongxu.arrary;

public class Test08 {
    public static void main(String[] args) {
        shangping[][] x =new shangping[4][];
        shangping x0 = new shangping(1,"鼠标","BZ",99.21,0.9);
        shangping x1 = new shangping(2,"键盘","WO",403.00,0.7);
        shangping x2 = new shangping(3,"程序","BK",89.00,0.8);
        shangping x3 = new shangping(4,"西装","GQ",700.00,0.5);
        shangping x4 = new shangping(5,"手机","DM",900,0.4);

        x[4][0] = x0;
        x[4][1] = x1;
        x[4][2] = x2;
        x[4][3] = x3;
        x[4][4] = x4;

        for(int i =0; i< x.length;i++) {

            for (int j = 0; j <x[i].length; j++) {
                System.out.print(x[i][j]);
            }
            System.out.println();
        }
    }
}
class shangping{
    private int id;
    private String mingcheng;
    private String xinghao;
    private double price;
    private double discount;

    shangping(){}

    public shangping(int id, String mingcheng, String xinghao, double price, double discount) {
        this.id = id;
        this.mingcheng = mingcheng;
        this.xinghao = xinghao;
        this.price = price;
        this.discount = discount;
    }

    @Override
    public String toString() {
        return "序号:"+getId()+"\t"+"名称:"+getMingcheng()+"\t"+"型号:"+getXinghao()+"\t"+"价格:"+getPrice()+"\t"+"折扣:"+getDiscount();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMingcheng() {
        return mingcheng;
    }

    public void setMingcheng(String mingcheng) {
        this.mingcheng = mingcheng;
    }

    public String getXinghao() {
        return xinghao;
    }

    public void setXinghao(String xinghao) {
        this.xinghao = xinghao;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }
}

shangping.png

JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 31425楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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